This tutorial will cover how PHP handles form data posted via the POST method. Show Introduction to the formPOST data is submitted by a form and “posted” to the web server as form data. POST data is encoded the same way as GET data, but isn't typically visible to the user in standard browsers. Most forms use the post method because it “hides” the form data away from the user and doesn't clutter up the URL in the address bar. Note that GET and POST methods are equally (in)secure. As easily as a user can monkey with GET data in a URL, the same thing can be done with POST data. You should always assume that the user can submit whatever form and form data that they want to, and process the data accordingly. Don't trust user input, whether it's from GET or from POST! Post data is accessed with the $_POST array in PHP.
Using “isset”You can use the “isset” function on any variable to determine if it has been set or not. You can use this function on the $_POST array to determine if the variable was posted or not. This is often applied to the submit button value, but can be applied to any variable. For example:
The above code will only display the submitted values if the submit button was clicked. Can I use both GET and POST in the same page?GET and POST occupy different spaces in the server's memory, so both can be accessed on the same page if you want. One use might be to display different messages on a form depending on what's in the query string.
Instead of using GET and POST arrays, you can also use the One more thing to notice: the “action” on the form is now missing. Technically, this is not valid HTML. However, by not putting in an action, browsers will assume that the form is submitting to itself. This is important because it will also preserve the querystring when the form is submitted (the ?lang=english part). You can use server
variables like For more information, see Using PHP_SELF in the action field of a form Register globals off?If you are using a version of PHP earlier than 4.2.0, you should strongly consider setting register_globals to “off” in your .htaccess file (if you are using Apache server) for the exact same reasons as were mentioned in the previous tutorial on GET. If you have PHP 4.2.0 or later, don't worry about it. More on POSTPOST values are unlimited in length, and thus are very well suited for forms, especially forms with a lot of fields. See Also
How get data from form submit in PHP?How to retrieve form data sent via GET. When you submit a form through the GET method, PHP provides a superglobal variable, called $_GET. PHP uses this $_GET variable to create an associative array with keys to access all the sent information ( form data ). The keys is created using the element's name attribute values.
How do I get form value on submit?To get input values on form submit in React:
Store the values of the input fields in state variables. Set the onSubmit prop on the form element. Access the values of the input fields in your handleSubmit function.
Can PHP collect form data?The PHP superglobals $_GET and $_POST are used to collect form-data.
What is used to retrieve values from HTML form in PHP?PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post".
|