...
/Submitting Data via the Request Body: Reviving Functionality
Submitting Data via the Request Body: Reviving Functionality
Let's restore the functionality of our application as it became broken after switching the form method from GET to POST.
We'll cover the following...
We'll cover the following...
Replacing GET with POST
Instead of $_GET['picture'] and $_GET['number'], we should use $_POST['picture'] and $_POST['number'].
If you replace every occurrence of $_GET with $_POST inside pictures.php, everything should work again.
Unfortunately, using $_POST instead of $_GET breaks the integration with /random.php.
As you may remember, it has a link to /pictures.php, and this link still adds a query parameter for the number of pictures to show.
We can do two things:
- Revert all the changes we made to
/pictures.php: Remove themethod="post"attribute, and go back to using query parameters and$_GET. - Add another form to
/random.php, which also submits its data as aPOSTrequest with a request body.
Option 1 is easy, but option 2 will be more interesting, so let’s do that.
Adding a form with a hidden field on random.php
On ...