PHP Forms Explained

September 28, 2022

This guide shows the basics of how PHP request methods work with PHP forms.

There are 2 ways PHP can interact with forms.

GET Method

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.

Example:

sample-newsletter-signup-form-min.png

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:

https://www.yourdomainname.com/yourscript.php?name=John&email=john@example.com

The data can then be accessed on the PHP landing page using the predefined variable $_GET:

<?php
echo "Name: ".$_GET['name']."<br>";
echo "Email: ".$_GET['email'];
/*
-- Output --
Name: John
Email: john@example.com
*/
?>

POST Method

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 $_POST.

<?php
echo "Name: ".$_POST['name']."<br>";
echo "Email: ".$_POST['email'];
/*
-- Output --
Name: John
Email: john@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!

Was this guide helpful?
Contact Support:

Our customer support team is available 24/7 and our average response time is between one to two hours.
Our team can be contacted via:

Support Forum: https://www.jotform.com/answers/

Contact Jotform Support: https://www.jotform.com/contact/

Send Comment:

Jotform Avatar
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Comment:

Podo CommentBe the first to comment.