php - Laravel executes the POST route upon loading page -
so have form on front page:
{{ form::open(array('url' => url::to('', array(), true))) }} <p> {{form::label('author') }} {{form::text('author') }} </p> <p> {{form::label('title') }} {{form::text('title') }} </p> <p> {{form::label('message') }} {{form::text('message') }} </p> <p> {{ form::submit() }} </p> {{ form::close() }}
then these routes:
route::get('/', function() { /* unrelated stuff here */ }); route::post('/', function() { /* testing */ print_r("done!"); exit; });
so trying test whether form submission works or not. , doesn't. reason post method being executed once load front page instead of when form submitted. why , how can fix this?
your form url should specified post / -
{{ form::open(array('url' => '/')) }}
in order redirect homepage should modify post method -
route::post('/', function() { /* testing */ print_r("done!"); return redirect::to('/'); });
here documentation redirecting.
Comments
Post a Comment