Jump to content

Selective $_POST superglobal ! ! !


pierrick

Recommended Posts

Hi all,

Can the superglobal $_POST be selective? I mean is there any reason it will pass data from a 'text', 'textarea' and drop-down list type input but not from a 'hidden' or 'checkmark' type input?

The most frustrating thing about this is that it was working perfectly a week ago and now even old code that worked great craps out!

I swear I never went near my php.ini either.

Any help greatly appreciated.
Link to comment
Share on other sites

Hi ober,

Here is some quick test code I rigged up to check what was going on:

[b]1. Form - all in HTML[/b]
<html>
<head>
<title>Test</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<form name='form1' method='post' action='test2.php'>
<p><input type="text" name="TextData1" maxlength="10" size="10" value="Test" /></p>
<p><input type="checkbox" name="TexData3" checked value="1" /></p>
    <p><textarea name="TextData4" rows="3" cols="20">Blah</textarea></p>
    <p><select name="TextData5" size="1">
    <option value="1">Option 1</option>
    <option selected value="2">Option 2</option>
    </select></p>
<p><input type="hidden" name="TexData2" value="2" /></p>
<p><input type="submit" name="formbutton1" value="Go" /></p>
</form>

</body>
</html>

[b]2. The result page (test2.php) with some php so I can display the vars[/b]
<html>
<head>
<title>Response</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<?php
if ( !empty( $_POST ) ) {
if ( isset( $_POST['TextData1'] ) ) {
$Var1 = $_POST['TextData1'];
echo "T1: '" . $Var1 . "'<br />";
}
if ( isset( $_POST['TextData2'] ) ) {
$Var2 = $_POST['TextData2'];
echo "T2: '" . $Var2 . "'<br />";
}
if ( isset( $_POST['TextData3'] ) ) {
$Var3 = $_POST['TextData3'];
echo "T3: '" . $Var3 . "'<br />";
}
if ( isset( $_POST['TextData4'] ) ) {
$Var4 = $_POST['TextData4'];
echo "T4: '" . $Var4 . "'<br />";
}
if ( isset( $_POST['TextData5'] ) ) {
$Var5 = $_POST['TextData5'];
echo "T5: '" . $Var5 . "'<br />";
}
}
?>

</body>
</html>

3. Browser display - when clicking button with default values:
T1: 'Test'
T4: 'Blah'
T5: '2'

Gone are the checkbox and hidden data...
Go figure...
???????????
Link to comment
Share on other sites

OK, I had a look at the old code that ran and don't no more. Couldn't figure it out so I went back to the above test code. I corrected the 2 silly typos and this is what I am getting:

1. If I click the submit button using the default values, all $_POST values are echoed in the browser
2. If I uncheck the check box I do not obtain a value for the $_POST['TextData3']

Still puzzled.
Link to comment
Share on other sites

Right on.

1. Same HTML form, typos fixed.
<html>
<head>
<title>Test</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<form name='form1' method='post' action='test2.php'>
<p><input type="text" name="TextData1" maxlength="10" size="10" value="Test" /></p>
<p><input type="checkbox" name="TextData3" checked value="1" /></p>
    <p><textarea name="TextData4" rows="3" cols="20">Blah</textarea></p>
    <p><select name="TextData5" size="1">
    <option value="1">Option 1</option>
    <option selected value="2">Option 2</option>
    </select></p>
<p><input type="hidden" name="TextData2" value="2" /></p>
<p><input type="submit" name="formbutton1" value="Go" /></p>
</form>

</body>
</html>

2. test2.php
<html>
<head>
<title>Response</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">

<?php
if ( !empty( $_POST ) ) {
if ( isset( $_POST['TextData1'] ) ) {
$Var1 = $_POST['TextData1'];
echo "T1: '" . $Var1 . "'<br />";
}
if ( isset( $_POST['TextData2'] ) ) {
$Var2 = $_POST['TextData2'];
echo "T2: '" . $Var2 . "'<br />";
}
if ( isset( $_POST['TextData3'] ) ) {
$Var3 = $_POST['TextData3'];
echo "T3: '" . $Var3 . "'<br />";
}
if ( isset( $_POST['TextData4'] ) ) {
$Var4 = $_POST['TextData4'];
echo "T4: '" . $Var4 . "'<br />";
}
if ( isset( $_POST['TextData5'] ) ) {
$Var5 = $_POST['TextData5'];
echo "T5: '" . $Var5 . "'<br />";
}
}
?>

</body>
</html>

There it is.
Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.