Adding a Tour
Explore how to build and validate a PHP form for adding tour data, manage POST requests with proper data types and default values, and store the submitted tours in a JSON file. Understand how to handle form checkboxes and avoid common PHP errors while ensuring data integrity.
Creating a form for tour data
What we really want is for the user to provide the data themselves, so we can save it.
Let’s start by adding includes for the good old _header.php and _footer.php files and showing a form for tour data.
The new form looks like this:
Using submitted data to add a new tour
Note that because the form element has its method attribute set to "post", the submitted data will end up in the $_POST superglobal.
Let’s take the data out and add it to $toursData instead of the hard-coded trip to Berlin:
Now go to http://APPLINK/create-tour again, fill out the form by providing a destination, a ...