pierrick Posted January 12, 2007 Share Posted January 12, 2007 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. Quote Link to comment Share on other sites More sharing options...
ober Posted January 12, 2007 Share Posted January 12, 2007 Umm... never heard of it being selective.[code]<?phpprint_r($_POST);?>[/code]Verify what is being passed. Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 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"><?phpif ( !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...??????????? Quote Link to comment Share on other sites More sharing options...
effigy Posted January 12, 2007 Share Posted January 12, 2007 Adding t's would help:Tex[tt][size=20pt]t[/size][/tt]Data2Tex[tt][size=20pt]t[/size][/tt]Data3If you would have used the print_r method as instructed, you would have seen these typos. Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 ???How dumb can one get????Thanks. Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 Having said that, it still doesn't explain why old code ain't working.... Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 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 browser2. If I uncheck the check box I do not obtain a value for the $_POST['TextData3'] Still puzzled. Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 Post some code. Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 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"><?phpif ( !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 Quote Link to comment Share on other sites More sharing options...
trq Posted January 12, 2007 Share Posted January 12, 2007 Actually, reading your post. I dont see a problem. If the xheckbox is NOT ticked, $_POST['TextData3'] will not exist. Thats how its meant to work. Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 Well, after today's fiasco, I'm going to go get meself a serious book on PHP.Apologies for wasting your time. Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 Thanks to all Quote Link to comment Share on other sites More sharing options...
pierrick Posted January 12, 2007 Author Share Posted January 12, 2007 Just trying to mark this thread as solved...Can't find the link they're talking about. Am I THAT blind? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.