Reputation: 317
I used POST method in my form to submit the value. Here is my form code:
<form action="{{ url('/') }}" method="POST">
<input type="hidden" name="value1" value="one" />
<input type="hidden" name="value2" value="two" />
<input type="submit" value="SEND!" />
</form>
and router.php code:
Route::get('/', function()
{
return View::make('index');
});
Route::post('/', function()
{
$data = Input::all();
var_dump($data);
});
whether every time I pressed SEND button it shows the index file. When I tried commenting out the get method. Now it shows a MethodNotAllowedHttpException
error. On error message it shows that request method is GET
What should I do now? Is that a bug? Or something wrong in my script?
Upvotes: 2
Views: 1984
Reputation: 230
See https://github.com/laravel/framework/issues/1804.
What I have seen is that Laravel removes all trailing '/' from the URL by redirecting to the url without '/' with code 301. Your browser will be follow this redirection with a GET request instead of a new POST request.
I had the same issue when posting to any url with a trailing '/'. Why don't you process the post at another url like '/post' to see if this is really the issue?
Upvotes: 1
Reputation: 6096
Which version of Laravel are you using? Laravel v4 comes with CSRF(Cross site request forgery) protection baked in. You need to include a hidden _token
field by getting Laravel to generate one for you use Form::token()
if you use Form::open()
method instead it will add the token field for you. Laravel will automatically look for that _token field and if it isn't found, or is not a correct token it will throw an exception.
Edit: Check out Filters.php in your app/ directory for more info on the CSRF filter.
Upvotes: 0