views:

59

answers:

2

I think that there is either an error in my code, or my PHP or Apache is set up incorrectly.

When I submit a form with a hidden field in it, I do not get any data in my $_POST array...

When I comment out the hidden field in my code, the POST data is returned correctly...

HTML FORM

<form action='/utils/login.php ' method='POST'>
<table>
    <tr>
        <td colspan='2'>
            Login
        </td>
    </tr>
    <tr>
        <td>
            Username
        </td>
        <td>
            <input type='text' name='userid' value='' size='12' />
        </td>
    </tr>
    <tr>
        <td>
            Password
        </td>
        <td>
            <input type='password' name='password' size='12' />
        </td>
    </tr>
    <tr>
        <td>
            <input type='hidden' name='formtype' value='login' />
        </td>
    </tr>
    <tr>
        <td>
            <input type='submit' value='Submit' />
        </td>
    </tr>
</table></form>

Here is the code that is processing it in PHP...

foreach ($_POST as $var => $value) {
     echo "$var = $value<br>";
} 

I am using PHP 5 and Apache 2.2 on my server.

Any ideas?

EDIT...

I have narrowed it down to this...

$command = $_POST['formtype'];

When I removed the @ sign from my $_POST, I am getting the following error...

Notice: Undefined variable: formtype in C:\webroot\utils\login.php on line 17

If I comment out that line, the POST data is passed into the program without a problem.

+1  A: 

I would suggest changing the code you are using to display the contents of $_POST to a single call:

print_r($_POST);

Anytime you are displaying the entire contents of an array, this is better than a loop w/ echo, as it will show every value at every level of the array.

Also, as was mentioned in a comment, make sure you close the form in the html.

JGB146
Thanks. I don't think that is the reason why the page is not returning any post data. Remember that when I comment out the <input type="hidden"> element entirely, POST back data is returned as expected.
Shane Larson
A: 

You never closed your <form> tag.

And I see now that someone beat me to it by a mile in the comments. Still, this is the right answer.

no