
Everyday we use some sort of form while surfing the Internet. Whether it be logging into our email, or registering a new account at the latest social media trend. Filling out forms has become a part of our lives, but have you ever thought of what happens after you press the submit button? Today we’ll talk about how to retrieve the information submitted from a form.
When a user presses the submit button on a form, there are two ways that the information can be sent to the server. One is sent via parameters in the URL, and the other (which is far more common) is sent via an HTTP request message. We’ll be talking about the latter today, which is called the POST method.
Within PHP, we have access to any data sent with through the POST method. We use the $_POST superglobal to access this data. This superglobal is an associative array of all of data past to use with the POST method. The id/name of the field is the key of the array, while what the user entered into the field is the value.
Text fields and password fields will always pass a value (even an empty one) to the script, while buttons, check boxes and radio buttons will only pass a value if they are clicked/selected. A drop down (or select) menu will pass the value of the selected option. Keep this information in mind when you’re checking if a field has text or is selected, as it will determine how you check for it. For fields that pass on a value regardless, you’ll check if it’s empty or not. For fields who only pass on a value when they’re selected, you’ll check if it’s set or not.
We’ll end this post by showing an example of a form and the code to process it. Example Code.





anorganix
April 14, 2009 10:11 am
alert(‘You should not allow JavaScript in comments!’);
blogadmin
April 14, 2009 11:07 am
I don’t think we do.