PHP Forms Explained

March 23, 2024

PHP forms consist of HTML elements and PHP scripts that enable users to input information. When a user submits a form, the data is sent to the server using the HTTP GET or POST method for processing. PHP scripts can then interact with the submitted data to perform various operations, such as inserting the information into a database or sending an email.

Youtube Embed Poster: ziEbQfchL3w

GET Method

The HTTP 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.

For example

<form action="welcome.php" method="GET">
  Name: <input type="text" name="name"><br>
  E-mail: <input type="text" name="email"><br>
  <input type="submit">
</form>

After submitting the form, the information will be sent to the server, and will include the form data in the URL similar to the following:

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

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

Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
 
<!--
**Output:**
Welcome John
Your email address is: john@example.com
-->

POST Method

Unlike GET, the HTTP POST method doesn’t include the data in the URL. This is ideal for collecting sensitive information because the data is not publicly visible.

For example

<form action="welcome.php" method="POST">
  Name: <input type="text" name="name"><br>
  E-mail: <input type="text" name="email"><br>
  <input type="submit">
</form>

After submitting the form, the data can be accessed on the PHP landing page using the predefined variable $_POST:

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

Each method has its advantages and disadvantages. Which one to use depends on your requirements and the purpose of your form. To get started with PHP forms, see PHP Form Generator.

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.

Podo Comment Be the first to comment.