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.
We’ll need the simple form set up from the Creating a simple form section.
How To do…
Follow these steps to complete this recipe:
1. Create a route to handle the POST data from the form:
// Process the data here
2. Create a route to redirect to, and to display the data:
return ‘Your username is: ‘ . Input::old(‘username’)
. ‘<br>Your favorite color is: ‘
How its work…..
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 do any processing of
the data, including saving to a database or validating the input.
In this case, we simply want to pass the data to the next page. There are a number of ways to
accomplish this. For example, we could use the Input class’s flashOnly() method:
However, we’re using a shortcut that Laravel provides, and only passing along two of the three
form fields we asked for.
On the next page, we use Input::old() to display the flashed input.