Asheeown Posted January 27, 2007 Share Posted January 27, 2007 This is a search for users to search through their own logs from different "sources" each source is a checkboxcode:[code] foreach($Source as $s) { if($_POST['Source[$i]'] == $s) { echo ("$s: <input name=\"Source[$i]\" type=\"checkbox\" id=\"Source[$i]\" value=\"$Source[$i]\" checked=\"checked\"/> "); } else { echo ("$s: <input name=\"Source[$i]\" type=\"checkbox\" id=\"Source[$i]\" value=\"$Source[$i]\" /> "); } $i++;}[/code]Now whats wrong with it is the checkboxes don't get checked...but I even printed the $_POST vars out before it and they say for $_POST['Source']:[quote][Source] => Array ( [0] => 000500 )[/quote]Any Ideas why they arent being checked? Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/ Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 What's $i? Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/#findComment-170258 Share on other sites More sharing options...
Asheeown Posted January 27, 2007 Author Share Posted January 27, 2007 $i is the variable that is making distinct names for the checkboxes[quote]name=\"Source[$i]\"[/quote]so for instance if two are called from the database it lists two with the names: Source[0] and Source[1] Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/#findComment-170259 Share on other sites More sharing options...
HuggieBear Posted January 27, 2007 Share Posted January 27, 2007 OK, I think I get it... Can you confirm the following for me.You display a form to the users that has a list of sources selected from the database, these are displayed as checkboxes on the page. How do we know if it should be checked or not, is there a value for that in the database?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/#findComment-170273 Share on other sites More sharing options...
Jessica Posted January 27, 2007 Share Posted January 27, 2007 is $s ever = 000500?print_r($Source) to make sure Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/#findComment-170276 Share on other sites More sharing options...
kenrbnsn Posted January 27, 2007 Share Posted January 27, 2007 Your code is wrong. Try this:[code]<?phpforeach($Source as $s) { $chkd = ($_POST['Source'][$i] == $s) ?' checked="checked"':''; echo $s . ': <input name="Source[' . $i . ']" type="checkbox" id="Source_' . $i . '" value="' . $Source[$i] . '"' . $chkd . '> '; $i++;}?>[/code]BTW, id values can not be arrays AFAIK.I also tightened the code somewhat...Ken Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/#findComment-170281 Share on other sites More sharing options...
Asheeown Posted January 27, 2007 Author Share Posted January 27, 2007 Yeah thanks ken realized all I need was to put the sub array outside the post array, thanks all Link to comment https://forums.phpfreaks.com/topic/35904-solved-form-post-var-not-registering/#findComment-170293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.