This guide shows the basics of how PHP request methods work with PHP forms.
There are 2 ways PHP can interact with forms.
The GET request method carries the form’s submitted data in the URL. This method displays the information in the URL including sensitive information. The advantage of using GET is users can bookmark the address with the data since the information is included in the URL.
After clicking the submit button, the information will be sent to the defined address on the form, and will include the form data in the URL similar to the following:
The data can then be accessed on the PHP landing page using the predefined variable
<?php echo "Name: ".$_GET['name']."<br>"; echo "Email: ".$_GET['email']; /* -- Output -- Name: John Email: firstname.lastname@example.org */ ?>
Unlike the GET method, the POST method doesn’t include the data in the URL. This is ideal for sensitive information collecting because the data is not visible to the public.
When the information is sent to the defined address on the form after submission, the form data is not visible in the URL. The data can be accessed on the PHP landing page using the predefined variable
<?php echo "Name: ".$_POST['name']."<br>"; echo "Email: ".$_POST['email']; /* -- Output -- Name: John Email: email@example.com */ ?>
Each method has its advantages and disadvantages. Which one to use depends on your requirements and the purpose of your form.
Get started with PHP Form Generator now!