I am building a practice app with the Laravel
framework I built a form in one of the views which is set to post to the same view itself but when I hit submit the form is posted however I do not get the desired output, I see the original view again.
Here is my view index.blade.php
@extends('master')
@section('container')
<div class="wrapper">
{{ Form::open(array('url' => '/', 'method' => 'post')) }}
{{ Form::text('url') }}
{{ Form::text('valid') }}
{{ Form::submit('shorten') }}
{{ Form::close() }}
</div><!-- /wrapper -->
@stop
and my routes.php
Route::get('/', function()
{
return View::make('index');
});
Route::post('/', function()
{
return 'successfull';
});
What I've tried so far
I tried changing the post to a different view and it worked. However I want the form to post to the same view itself.
Instead of returning a string I tried to return make a view still it didn't work.
What am I doing wrong?
addendum
I see that when the form is making the post request I am getting a 301 MOVED PERMANENTLY HEADER
Well, you just return the view, so nothing change. You should bind your route to a controller to do some logic and add data to your view, like this:
index.blade.php
Your routes
You controller
HomeController.php
You can also modify your current routes without using a controller like this (use the new view file)
You need to make sure that your form's method does NOT end in a / for it to be routed correctly. For example if you have the following route:
Then you need to have the following form definition:
I hope that helps.
There is some helpfull information in the Laravel Docs. Check these out:
I recommend you read the Resource Controllers documentation as it makes form handling a lot easier.
Passing a space as the url has worked for me.
I have same problem with OSx + MAMP, initially I've resolved with Raul's solution:
but after consultation with my friend we have concluded that my problem was due to the fact my lavarel project is avaliable by long local path, as:
in this location the post/get method on root path ("/") not working correctly.
Lavarel to working correctly must be avaliable by "vhost", in this case the problem get/post method on root location "/" not exist.
My friend advised me to use http://www.vagrantup.com/
BYE
I think this post: Form submits as GET Laravel 4 is related to your problem. I think the problem as I undersood it is caused by end a form url with a / . I found this when having problems to using post to a ./ url in my form. There is also a bug at github that seems like it is related https://github.com/laravel/framework/issues/1804.
I know this is an old question but I found this thread having the same problem so hopefully someone else is helped by my answer.