Reputation: 5428
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.
Upvotes: 9
Views: 39382
Reputation: 320
That suggest you create a textfield that you populate with the id from the drop down list whenever changed. When you post the form the textbox will show the previous id of the drop down list. You can set the textfield to hidden
Upvotes: 0
Reputation: 51
You never can pass a value to another page using the id, the only attribute that php can read via methos POST is using the name of the object.
Upvotes: 1
Reputation: 798676
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.
Upvotes: 11