---
title: "Form Handling in PHP"  
description: "Information sent by the user are visible to everyone (all name and values are displayed in the URL). So, GET method cannot be used to send sensitive i"  
author: "Samuel Fernandes"  
published: 2016-06-06  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/12155/form-handling-in-php  
category: "php"  
tags: ["php", "handler"]  
reading_time: 3 minutes  

---

# Form Handling in PHP

In previous article we discussed about [loop in php](https://www.mindstick.com/Articles/12154/loop-in-php). Now we discuss about form handling in php\

##### GET Method

Information sent by the user are visible to everyone (all name and values are displayed in the URL). So, GET method **cannot**be used to send sensitive information (like password).Get also has limitation on the amount of information to be send. The limitation is about 2000 characters. Get method is used to bookmark the pages.

**Note**: Get method should never be used to send password or other sensitive information. Here is an example to show how to use GET method:

Step 1: create a form (form.php)

```
// action is used to send the information on getmethod.php
<form method="get" action="getmethod.php">//As we have used get method in the form, so we have  to use $_GET or $_REQUEST but not $_POST (mandatory).
Name:<input type="text" name="name">Age:<input type="number" name="age"><input type="submit" name="submit">
</form>
```

\

Step 2: getmethod.php.

```
<?phpif(isset($_GET["submit"]))  //$_GET is a superglobals  variable used to receive sent information at server end.
{$name=$_GET["name"];$age=$_GET["age"];echo "Name of student:  $name. </br>";echo "Age of student:   $age";}?>
```

![Form Handling in PHP](https://www.mindstick.com/mindstickarticle/9ed67acb-f7e8-4a46-b6c1-9dd202345b08/images/25bc78ba-8b38-4fc5-b1db-6244cfb8a5b0.png)

##### POST Method:

Unlike GET method, information sent by the user is hidden in case of POST method. Developers mainly used POST method.POST method does not have limitation on amount of information to send. As variables are not shown in URL so it is not possible to bookmark the page.

##### NOTE: To send sensitive information use only POST method:

Step 1: create a form (form.php)

```
<form method="post" action="postmethod.php">//As we have used post method in the form, so we have    to use $_POST or $_REQUEST but not $_GET (mandatory).
Name:<input type="text" name="name">Age:<input type="number" name="age"><input type="submit" name="submit">
</form>
```

Step 2: Create postmethod.php

```
<?php
if(isset($_POST["submit"]))"]))  //$_POST is a superglobals  variable used to receive sent information at server end.
{$name=$_POST["name"];$age=$_POST["age"];echo "Name of student:  $name. </br>";echo "Age of student:   $age";}?>
```

![Form Handling in PHP](https://www.mindstick.com/mindstickarticle/9ed67acb-f7e8-4a46-b6c1-9dd202345b08/images/85ef7e5c-623a-41b7-bedd-5d05913e9394.png)

**NOTE:** **$_REQUEST** is an associative array that by default contains the content of $_POST, $_GET and $_COOKIE which is used to receive information whether the method is POST or GET.

Step 1: Create a form. (form.php)

```
//Form is created
<form method="post" action="phpintro.php">Name:<input type="text" name="name">Age:<input type="number" name="age"><input type="submit" name="submit"></form>
```

Step 2: Receive information using $_REQUEST:

```
<?phpif(isset($_REQUEST["submit"])) // $_REQUEST used to receive information. But we cannot use $_GET
{$name=$_REQUEST["name"];$age=$_REQUEST["age"];echo "Name of student:  $name. </br>";echo "Age of student:   $age";}?>
```

\

Similarly, in case of get method we can use $_REQUEST method to receive the information.

Step 1: Create a form.

```
//Form is created<form method="get" action="phpintro.php">Name:<input type="text" name="name">Age:<input type="number" name="age"><input type="submit" name="submit"></form>
```

Step 2: Receive information using $_REQUEST:

```
<?phpif(isset($_REQUEST["submit"])) // $_REQUEST used to receive information. But we cannot use $_POST
{$name=$_REQUEST["name"];$age=$_REQUEST["age"];echo "Name of student:  $name. </br>";echo "Age of student:   $age";}
?>
```

---

Original Source: https://www.mindstick.com/articles/12155/form-handling-in-php

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
