Forms are the bridge between the visitor and your PHP code. When a user fills in a field and submits, the data arrives on the server.
On the HTML side
- The <form method= »post » action= »process.php »> tag defines where and how to send the data.
- Every field has a name attribute, e.g. <input name= »firstname »>.
On the PHP side
PHP receives this data in the superglobal array $_POST. You read a field by its name: $_POST[« firstname »].
- Check that the field exists with isset($_POST[« firstname »]).
- Store the value in a variable.
- Use it (display it, save it and so on).
There is also $_GET, which passes data through the URL. $_POST is preferable for sensitive or large amounts of data.
Key point: every field needs a name, and PHP reads its values from $_POST. Always check it exists with isset.