Jump to content

Missing $_POST array values


SeanF

Recommended Posts

I have a form which has been working perfectly well for one user for a couple of years. Now, I have added a new user and the form fails for that one user. (I can't see a difference in user configuration.)

The problem is that when the form is submitted using the following button:

Quote

<input type='submit' name='submit' value='Next'>


The form is submitted but it returns with no values set and does not process any of the form data. Even echoing out $_POST['submit'] returns a null value

I have placed the following code at the top of the page:

Quote

$test = $_POST['test'];
echo "test: $test<br/>";


And then placed the following code in the body of the form:

Quote

echo "Hidden Test is here: <br/>
<input type='hidden' name='test' value='Test'>";


When the page first loads "test" is NULL as one would expect.

If I place the "test" hidden input element at the top of the form and click "Next" the value of test is "Test"... correct
If I place the "test" hidden input element at the bottom of the form and click "Next" the value of test is NULL

By moving the hidden input I have found that there is a specific part of the form which is causing a problem. If the input element is before the code, "test" has a value. If it is after that code, "test" is null.

The offending code is here:

Quote

echo "
<p>Please indicate below your space preferences below. </p>
<table border=$table_border>
<tr>
<td>1st Choice: <input type='text' name='first_choice' size=15 maxlength=25> </td>
<td>2nd Choice: <input type='text' name='second_choice' size=15 maxlength=25> </td>
<td>3rd Choice: <input type='text' name='third_choice' size=15 maxlength=25> </td>
</tr>
<tr>
<td colspan='3'>
 We would prefer <b><i>to</i></b> exhibit next to the following companies:
 <input type='text' name='next_to' size=50 maxlength=75>
</td>
</tr>
<tr>
<td colspan='3'>
 We would prefer <b><i>not to</i></b> exhibit next to the following companies:
 <input type='text' name='not_next_to' size=50 maxlength=75>
</td>
</tr>
</table>
";


I can't for the life of me figure out why this is causing a problem.

Any thoughts would be greatly appreciated

Link to comment
Share on other sites

1 hour ago, Barand said:

If that is the offending code, where is the hidden "test" input of which you speak?

You need to post the whole of the code for the form, from <form> to </form>

The "test" input is in the quote box immediately following "And then placed the following code in the body of the form:"  I place that echo statement either immediately before or immediately after the echo statement which is the "offending code"

when the "input" is before the "offending code" all $_POST variables are set as expected.  When the "input" is after, all of the $_POST['test'] is null as are all the $_POST variables from that point on

Thanks again

Link to comment
Share on other sites

Great.  

Thank you for pointing out the validator site. This is old code from an application I wrote about 18 years ago and there is a LOT of outdated syntax.  I have a lot of work to do but at least now I know where to start.

Thanks again

Link to comment
Share on other sites

Along with validation, using the developer tools is an excellent iterative way to explore the state of the DOM, and to find syntax errors in javascript, or to explore layout and effective styles.    The network tab is also extremely valuable, in examining request/response data for ajax or regular form processing via get or post requests.  That should always be your first step in starting to debug things.  Most modern code editors people use to develop PHP with will also catch a lot of syntax errors, although code that renders html will typically look valid so long as the php code is valid.  Moving html into a template engine, or even making use of heredoc and nowdoc is helpful in many ways to separate markup from your logical code.

Link to comment
Share on other sites

On 7/6/2023 at 9:41 AM, gizmola said:

... Most modern code editors people use to develop PHP with will also catch a lot of syntax errors, ...

Thanks for the input.  What would you suggest as a good editor for PHP coding?  I have been using "BBedit" for years but I am sure there's a better editor that would help me.

Thanks again

Link to comment
Share on other sites

If you can afford it, PHPStorm is pretty much the professional standard.  A lot of people also use visual studio code, in combination with the "Intelephense" plugin.  Intelephense provides a good number of features for free, but you can also license it for $20 to unlock the rest of the features, which I would highly recommend.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.