Gathering form input to display on another page
After a user submits a form, we need to be able to take that information and pass it to another page. This recipe shows how we can use Laravel's built-in methods to handle our POST data.
Getting ready
We'll need the simple form set up from the Creating a simple form section.
How to do it...
Follow these steps to complete this recipe:
Create a route to handle the POST data from the form:
Route::post('userform', function() { // Process the data here return Redirect::to('userresults')- >withInput(Input::only('username', 'color')); });
Create a route to redirect to, and to display the data:
Route::get('userresults', function() { return 'Your username is: ' . Input::old('username') . '<br>Your favorite color is: ' . Input::old('color'); });
How it works...
In our simple form, we're POSTing the data back to the same URL, so we need to create a route that accepts POST
using the same path. This is where we would...