Form Handing in PHP
In PHP, We can create and use forms to get data from a Form. To read or get data from a form, we need to use SuperGlobal Variables. A Superglobal variable is a built in PHP variable that is available in any scope.
PHP supports two superglobal variables, Those are
- $_GET
- $_POST
- contains list of all input element names and values sent by a form using the get method.
- contains list of all input element names and values sent by a form using the post method.
In simple words, the form request generated through may be get or post method. To retrieve data from get request, we need to use $_GET, To retrieve data from post request, we need to use $_POST.
Now, we going to learn about Get and Post forms with suitable examples.
Get Form :
Get form is a form which is generated through get request. The get request is the default form request. The data passed through get request is visible on the URL so it is not secured. And we can able send limited amount of data through get request.
Here, I am attaching an example to work with get request form, which consists two programs one is HTML file(GetForm.html) to create an user interface and second one is PHP file(getform.php) to read data from HTML input elements.
Example:

When the user clicks on the "Click Me" button the following PHP script file gets executed. The PHP script reads the data from HTML form elements using $_GET superglobal variable and then displays on the screen.

Post Form :
Post form is a form which is generated through post request. The post request is not a default form request. The data passed through post request is not visible on the URL so it is secured. And it allows you send unlimited amount of data.
The Post request is widely used to submit form that have large amount of data such as file upload and sensitive data such as login form, registration form etc.
Here, I am attaching an example to work with post request form, which consists two programs one is HTML file(PostForm.html) to create an user interface and second one is PHP file(postform.php) to read data from HTML input elements.
Example:

When the user clicks on the "Login" button the following PHP script file gets executed. The PHP script reads the data from HTML form elements using $_POST superglobal variable and then displays on the screen.

Example Programs
☞ Reading data from Radio Button


☞ Reading data from Selection List(Dropdown List)

