Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Last active August 29, 2015 14:13
Show Gist options
  • Save tommymarshall/e90112157a8d76c6d4f1 to your computer and use it in GitHub Desktop.
Save tommymarshall/e90112157a8d76c6d4f1 to your computer and use it in GitHub Desktop.
Route::post() requests never get matched, requests always end up matching Route::get(). Here's a gif of what's happenning: http://cl.ly/image/3s0X0q2p0r1o
<?php
class PagesController extends BaseController
{
public function home() {
return View::make("pages.home");
}
public function about() {
return View::make("pages.about");
}
public function vision() {
return View::make("pages.vision");
}
public function subscription() {
return View::make("pages.subscription");
}
public function create() {
die(var_dump(Input::all()));
exit;
}
}
<?php
// Home
Route::get('home', 'PagesController@home');
// Pages
Route::get('page', [['about'], 'uses' => 'PagesController@about']);
Route::get('page', [['vision'], 'uses' => 'PagesController@vision']);
Route::get('page', [['subscription'], 'uses' => 'PagesController@subscription']);
// Subscription
Route::post('page', [['subscription'], 'uses' => 'PagesController@create']);
@extends('layouts.base')
@section('content')
<h1>Subscribe</h1>
{{ Form::open('subscription') }}
Name: <input type="text" name="name" id="name"><br>
Email: <input type="email" name="email" id="email"><br>
<input type="submit" value="Submit">
{{ Form::close() }}
@stop
@tommymarshall
Copy link
Author

I expect that PagesController@create should be fired when I submit the form on subscription.scout.php, but it never does. Instead, the request matches the get request for the subscription uri.

@jlambe
Copy link

jlambe commented Jan 14, 2015

You expect the right behavior ;) I found your issue. WordPress is kind of a bitch because it has some reserved variables that you can't use for your input attributes. Check this page for a list of input names to avoid: http://codex.wordpress.org/WordPress_Query_Vars#Query_variables

The issue is your name input attribute name. When you develop with WordPress it is best practice to prefix your name attributes. Simply replace your attribute value like this for example app_name and it should work as expected.

Also, in order to output some inputs, you can leverage the Form class:

Form::text('app_name');
Form::email('app_email');
Form::submit('submit', 'Submit');

Let me know if this fix your issue. Cheers ;)

@tommymarshall
Copy link
Author

That did it :) Awesome! Thank you.

@jlambe
Copy link

jlambe commented Jan 14, 2015

Great 😄 A 1.1.1 minor update should be available for the end of the week so you'll be up to date for using the framework on your projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment