Page 1 of 1
Known problems with hidden fields and forms?
Posted: Tue Jan 21, 2003 9:44 am
by MattSharp
I have a form that only contains one field and its hidden. This is used so that we can use submit buttons to select which option the person wants. I realize there are more practical ways to do this but I am reconfiguring a script and eventuall will re-do it better, but for the time being this is how it is done. The script worked previously, but after recently upgrading to a newer version of PHP I have run into a rather odd problem. When I pass one hidden field in via POST and output it on the next name it shows up in the form as name=value (of course it should just be value). If I add a second hidden field to the form and run it, everything works fine. Has anyone heard of or seen this problem before? Is there anything I can do/try short of adding a dummy hidden field to each form this is used in?
Posted: Tue Jan 21, 2003 9:46 am
by twigletmac
Could we see the form code and the bit of code you use to display it on the next page?
Mac
Posted: Tue Jan 21, 2003 11:00 am
by hedge
I have hade some strange things like that, usually comes back to having slight errors in the html. Missing quotes or end tags have been my nemesis.
Posted: Tue Jan 21, 2003 11:20 am
by MattSharp
twigletmac wrote:Could we see the form code and the bit of code you use to display it on the next page?
Mac
Form Code:
Code: Select all
<form method="POST" action = "options.php">
<input type="hidden" name="machine" value="thisone" />
<input type="submit" value="Select" /> This one (This one)
</form>
Display
Code: Select all
<font size="2" color="black">Test: <?=$machine?></font><br />
As I said if I add a second hidden field to the the form then both display properly.
Posted: Wed Jan 22, 2003 9:03 am
by MattSharp
Any further advice?
Posted: Wed Jan 22, 2003 9:21 am
by twigletmac
Have you tried:
Code: Select all
<font size="2" color="black">Test: <?php echo $_POST['machine']; ?></font><br />
(note that the forum decided to remove the closing php tag - ? >)
and what do you get if you put
Code: Select all
echo '<pre>';
print_r($_POST);
echo '</pre>';
at the top of the form processing page?
Mac
Posted: Wed Jan 22, 2003 10:06 am
by MattSharp
Yes I tried that, it produced the same result. Your second test produced this result.
Array
(
[key] => VALUEkey=VAULE
)
Where key is the name and VALUE is the value.
Posted: Wed Jan 22, 2003 10:13 am
by volka
if you switch the form's method from "POST" to "GET" what does the url look like after you pressed "submit"?
Posted: Wed Jan 22, 2003 10:21 am
by MattSharp
volka wrote:if you switch the form's method from "POST" to "GET" what does the url look like after you pressed "submit"?
That works correctly.
EDIT: Both the URL and the variables.
Posted: Wed Jan 22, 2003 12:20 pm
by volka
you might want to try
- php.ini: always_populate_raw_post_data = On
- or .htaccess: php_flag always_populate_raw_post_data On
to see what $HTTP_RAW_POST_DATA contains.
Code: Select all
<html><body>
<?php echo htmlentities($HTTP_RAW_POST_DATA); ?>
<form method="POST">
<input type="hidden" name="machine" value="one" />
<input type="hidden" name="machine" value="two" />
<input type="submit" value="Select" />
</form>
</body></html>
is
mbstring or another conversion active?
Posted: Wed Jan 22, 2003 12:35 pm
by MattSharp
volka wrote:you might want to try
- php.ini: always_populate_raw_post_data = On
- or .htaccess: php_flag always_populate_raw_post_data On
to see what $HTTP_RAW_POST_DATA contains.
Code: Select all
<html><body>
<?php echo htmlentities($HTTP_RAW_POST_DATA); ?>
<form method="POST">
<input type="hidden" name="machine" value="one" />
<input type="hidden" name="machine" value="two" />
<input type="submit" value="Select" />
</form>
</body></html>
is
mbstring or another conversion active?
That code doesn't output anything.....
Posted: Wed Jan 22, 2003 1:14 pm
by volka
it only does if always_populate_raw_post_data is enabled.
check with
the local value for always_populate_raw_post_data must be 1
e.g.
Code: Select all
Configuration
PHP Core
Directive Local Value Master Value
allow_call_time_pass_reference Off Off
allow_url_fopen 1 1
always_populate_raw_post_data 1 0
arg_separator.input & &
arg_separator.output & &
Posted: Mon Jan 27, 2003 11:11 am
by MattSharp
volka wrote:it only does if always_populate_raw_post_data is enabled.
check with
the local value for always_populate_raw_post_data must be 1
e.g.
Code: Select all
Configuration
PHP Core
Directive Local Value Master Value
allow_call_time_pass_reference Off Off
allow_url_fopen 1 1
always_populate_raw_post_data 1 0
arg_separator.input & &
arg_separator.output & &
Upoon testing the output of what you told me to I got:
VALUEmachine=VALUE;
Now, I guess I just have to put an extra data field in that does nothing, although I don't know why. Could this problem and the other problem I am having with uploading files be contributed to a bad install of PHP?