I am a beginner with PHP and I would really like to understand it a lot better. I know you can use $_POST to retrieve information from a form by setting method=”$_POST”. But why does this work exactly? Is, upon form submission, an array named $_POST created? Does the array then contain all of the element values from the form?
Share
When you press the submit button, your client will send a HTTP POST request to the script specified in
action. In your situation, the values filled in the form will be sent as parameters in this request (note that a client can potentially send anything in a GET/POST request; this is important to know for security). PHP will put those parameters in the$_POSTsuperglobal so the script can do something with the form data.Forms aren’t the only source of POST data, both in theory and in practice. For example, an API could accept HTTP POST requests, and Javascript can let a browser perform passive asynchronous requests using AJAX.