Can someone please explain this to me?
I have the following code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" id="testField" />
<input type="submit">
</form>
<br /><br />
<pre>
<?php print_r($_POST); ?>
</pre>
This works fine on my main dev box, and on the server. However, I'm having to work remotely on my laptop at the moment. I've installed the exact same WAMPServer 2.1a build as on my dev setup, and the $_POST array is empty.
If I declare the field like:
<input type="text" name="testField" />
I get the expected output.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. The example below shows a form with an input field and a submit button.
The PHP built-in variable $_POST is also an array and it holds the data that we provide along with the post method.
The $_POST variable is an array of variable names and values sent by the HTTP POST method. The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
POST is used to send data to a server to create/update a resource.
Standard behavior. Always use name
within form.
From the HTML 4.01 specification, §17.2, "Controls":
A control's "control name" is given by its name attribute.
...
When a form is submitted for processing, some controls have their name paired with their current value and these pairs are submitted with the form.
"id" does not matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With