How to recevethe data sent from a form in php by using php form variable get , post or request method?

php form variable

 

To generate business online and to get connected with business and website user form submission is the ultimate way. But form after submission of the form has to receive the data and use them also, so in this post we are going to learn how to receive the data sent from a form in PHP by using PHP form variable get , post or request method.

How to submit a form, from HTML to PHP?

To submit an HTML form there must have an action that will submit the form in a targeted page, a method that indicts the submission method of the form and also a ency type. There should be some field inside the form and also a submit button to make the submit event.

A sample HTML form is given below:

<html>
<body>

<form action=”welcome_post.php” method=”post”>
Name: <input type=”text” name=”name”>
Contact No: <input type=”text” name=”contact_no”>
<input type=”submit”>
</form>

</body>
</html>

 

in case if want to send the value through get method then have to change the method of form to get and then the code of the form will be as described below,

<html>
<body>

<form action=”welcome_post.php” method=”post”>
Name: <input type=”text” name=”name”>
Contact No: <input type=”text” name=”contact_no”>
<input type=”submit”>
</form>

</body>
</html>

 

How to get the value submitted through get method in PHP?

First need to know what gets method, while a form is submitted in a get method the values are sent through the URL, so using browser history the anyone can find the value so the values sent from getting method are less secure. Also, all browsers can be sent a limited amount of data through URL so less amount of data can be sent through the get method.

now to get the value in PHP sent through get method is, $_GET thus all the get value can be fetched as an array of GET variable, so to get a particular value to have to pass the input fields name as a get method array key.

An example of PHP get method is given below:

<?php
echo ‘Name= ‘ . $_GET[“name”] . ‘<br/>’;
echo ‘And Contact No = ‘ . $_GET[“contact_no”];
?>

 

How to get the value submitted through the post method in PHP?

After a form submission unlike get method, the value is not sent through the URL so no one can be able to get the values submitted by post method, The amount of data is limited by the server only so a vast amount of data can be sent through the post method like image or video, etc.

now to receive the value in PHP sent through post method is, $_POST thus all the post value can be fetched as an array of POST variable, so to get a particular value to have to pass the input fields name as a POST method array key.

An example of PHP POST method is given below:

<?php
echo ‘Name= ‘ . $_POST[“name”] . ‘<br/>’;
echo ‘And Contact No = ‘ . $_POST[“contact_no”];
?>

 

Different between GET and POST method,

Both GET and POST create an array. The array holds key/value, where keys are the names of the form input fields and values are the data given as input in the form fields by the user.

Both GET and POST are treated as $_GET and $_POST. These are superglobal, That is they are accessible inside or outside of scope or functions.

$_GET is an array of variables passed through the URL which is visible to all user.

$_POST is an array of variables passed through the HTTP POST method which is not visible by all users.

And also it can be said that through get method we can sand less amount of data where through the post method we can send a greater amount of data.

The amount of data sent through get method is dependable on browser and PHP both as PHP have its data limit and the browser has its URL length limit. but the data sent through the post method is depending on the PHP only that how much data limit is there.

PHP Form Variable $_REQUEST

Using $_REQUEST in PHP can be received array data sent through get or post method from an HTML form.

an example of $_REQUEST is given below:

<?php
echo ‘Name= ‘ . $_REQUEST[“name”] . ‘<br/>’;
echo ‘And Contact No = ‘ . $_REQUEST[“contact_no”];
?>

 

PHP Form Variable $_REQUEST, $_POST and $_GET

All the three PHP form variable $_REQUEST, $_POST and $_GET are super global and array type variable. that is it can be receive data from inside or outside of scope or function.

In this post we have gone through how to receive the data sent from a form in PHP by using PHP form variable get, post or request method. I hope that you are able to get a clear idea of the PHP form variable.

Thanks for reading.

Share The Post On -

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.