denoteone Posted January 27, 2009 Share Posted January 27, 2009 I have a form that ask the user to check all that apply (among other questions). On submit the next page shows all the users answers. Giving them a chance to go back if they want to change one. I am having problems with the checkboxes here is my code from both pages. check all that apply <INPUT TYPE=hidden NAME="relationship" Value="0"><br/> <INPUT TYPE=CHECKBOX NAME="relationship" value="IT">Information Technolody<br/> <INPUT TYPE=CHECKBOX NAME="relationship" value="Purchasing">Purchasing<br/> <INPUT TYPE=CHECKBOX NAME="relationship" value="Marketing">Marketing<br/> <INPUT TYPE=CHECKBOX NAME="relationship" value="Human_Resources">Human Resources<br/> <INPUT TYPE=CHECKBOX NAME="relationship" value="Executive_Management">Executive Management</p><br/> this is what is on the confirm page so the user can see what they checked and then submit. This is the list that you checked: <?=$_POST['relationship']?><input type="hidden" value=" <?=$_POST['relationship']?>" name="relationship" /> Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/ Share on other sites More sharing options...
printf Posted January 27, 2009 Share Posted January 27, 2009 PHP does checkboxes and multi select boxes as array elements <INPUT TYPE=hidden NAME="relationship[]" Value="0"><br/> <INPUT TYPE=CHECKBOX NAME="relationship[]" value="IT">Information Technolody<br/> <INPUT TYPE=CHECKBOX NAME="relationship[]" value="Purchasing">Purchasing<br/> <INPUT TYPE=CHECKBOX NAME="relationship[]" value="Marketing">Marketing<br/> <INPUT TYPE=CHECKBOX NAME="relationship[]" value="Human_Resources">Human Resources<br/> <INPUT TYPE=CHECKBOX NAME="relationship[]" value="Executive_Management">Executive Management</p><br/> Then foreach ( $_POST['relationship'] AS $name = $value ) { echo $value . "<br />"; } Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/#findComment-747885 Share on other sites More sharing options...
denoteone Posted January 27, 2009 Author Share Posted January 27, 2009 but I still need to save that array somewhere so when they confirm everything is "ok" the relationship array needs to be the value of a hidden input. Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/#findComment-747889 Share on other sites More sharing options...
printf Posted January 27, 2009 Share Posted January 27, 2009 <input type='hidden' name="relationship" value="<?php echo htmlentites ( serialize ( $_POST['relationship'] ) ); ?>" /> Then when it comes back into your script... $_POST['relationship'] = unserialize ( $_POST['relationship'] ); Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/#findComment-747893 Share on other sites More sharing options...
denoteone Posted January 27, 2009 Author Share Posted January 27, 2009 parse error: parse error, unexpected '=', expecting ')' in /home/content/t/w/e/t######/html/####/New_opcheck.php on line 75 this is line 75 foreach ( $_POST['relationship'] AS $name = $value ) Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/#findComment-747895 Share on other sites More sharing options...
printf Posted January 27, 2009 Share Posted January 27, 2009 Change to... (was missing the ">") foreach ( $_POST['relationship'] AS $name => $value ) Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/#findComment-747896 Share on other sites More sharing options...
denoteone Posted January 27, 2009 Author Share Posted January 27, 2009 it does work. I guess I am just not sure why. Could you provide a quicke xplination. I understand that it saves the value in an array named relationships. and then loops and echos all the values....what is the AS $name => $value for? Link to comment https://forums.phpfreaks.com/topic/142685-solved-post-data-from-checkbox/#findComment-747900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.