Devon
Devon

Reputation: 27

$_POST is empty when submitting a value that was posted to the form

I am pretty new to web programming and I cannot figure this problem out. To keep things simple, say I have 2 pages. The first page has a form with two selection boxes and a submit button. The second page has a form with two text input boxes and a submit button. After the form on the first page is submitted it goes to the second page and the two text input boxes are filled with the values from the first form with a $_POST.

My problem is, when I submit the second form (which goes to the same second page on submit) the $_POST variables of the form are empty.

I thought the if-else in the value would fix it. The purpose of that was because after submitting the $_POST from the previous page no longer has a value and I want the value in this forms field to be displayed after submitting (which is still the same value from the first form). Not only do I want it to display the value in these fields, I want to use them for a database query (which is why them being blank is a problem).

The values in the form when the second page is reached are correct. Also in the else case if I echo "test" instead of the $_POST it is displayed in the box so I believe I have it narrowed down to the $_POST being blank after submitting but I have no idea why.

<form method="post" action="newSerialNumber.php">
    JON: <input type="text" name="newSNJON" value="<?php if ($_POST['JON'] != ""){ echo $_POST['JON'];}else{ echo $_POST['newSNJON'];} ?>" disabled> 
    Part Number:  <input type="text" name="newSNPN" value="<?php if ($_POST['PN'] != ""){ echo $_POST['PN'];}else{ echo $_POST['newSNPN'];} ?>" disabled>
    <input type="submit" name="Button" value="Add">
</form>

Upvotes: 0

Views: 1041

Answers (2)

C3roe
C3roe

Reputation: 96151

You have the disabled attribute set in those input fields.

Disabled form elements are not send when the form is submitted.

http://www.w3.org/TR/html5/forms.html#attr-fe-disabled:

“The disabled attribute is used to make the control non-interactive and to prevent its value from being submitted.”

If you don’t want the user to be able to change the values, but still send them with the form when it is submitted – use the readonly attribute instead.

Upvotes: 3

schellingerht
schellingerht

Reputation: 5796

Yes, it's right.

Disabled fields are not included in the submit. Remove the disabled attributes and you can see it works.

Upvotes: 1

Related Questions