Pavlos1316 Posted July 9, 2008 Share Posted July 9, 2008 hi i have a checkboxes form with 4 boxes. i need user to choose 3. if he chooses 2 the procces.php tells him to choose another one. i did that. but how to i get, when a user chooses only two and procces.php refresh the page, not to clear the 2 checkboxes that he chose. thank you Link to comment https://forums.phpfreaks.com/topic/113873-solved-refresh-checkboxes-form/ Share on other sites More sharing options...
bluejay002 Posted July 9, 2008 Share Posted July 9, 2008 you need to store it then refer it back when refreshed. Link to comment https://forums.phpfreaks.com/topic/113873-solved-refresh-checkboxes-form/#findComment-585155 Share on other sites More sharing options...
Pavlos1316 Posted July 9, 2008 Author Share Posted July 9, 2008 can you help me here? Link to comment https://forums.phpfreaks.com/topic/113873-solved-refresh-checkboxes-form/#findComment-585158 Share on other sites More sharing options...
bluejay002 Posted July 10, 2008 Share Posted July 10, 2008 here is a simple implementation but may change once specially if checkboxes are variables. <?php $check = array(); if(isset($_POST['1'])) $check[] = $_POST['1']; if(isset($_POST['2'])) $check[] = $_POST['2']; if(isset($_POST['3'])) $check[] = $_POST['3']; if(isset($_POST['4'])) $check[] = $_POST['4']; ?> <html> <head> <title>Checkbox</title> </head> <body> <?php $all = count($check); $at = ($all == 0) ? 1 : 0; ?> <br /> <form target="_self" method="post"> <input type="checkbox" id="1" name="1" value="1" <?php if($at <= $all && $check[$at] == 1) {echo 'checked'; $at++;}?>/> <input type="checkbox" id="2" name="2" value="2" <?php if($at <= $all && $check[$at] == 2) {echo 'checked'; $at++;}?>/> <input type="checkbox" id="3" name="3" value="3" <?php if($at <= $all && $check[$at] == 3) {echo 'checked'; $at++;}?>/> <input type="checkbox" id="4" name="4" value="4" <?php if($at <= $all && $check[$at] == 4) {echo 'checked'; $at++;}?>/> <input type="submit" value="CLICK" /> </form> </body> </html> Happy programming! Jay, Link to comment https://forums.phpfreaks.com/topic/113873-solved-refresh-checkboxes-form/#findComment-585973 Share on other sites More sharing options...
Pavlos1316 Posted July 17, 2008 Author Share Posted July 17, 2008 Hi From the day you answered me just now I found time to test your code and is working just fine!!!! Thanks a lot mate. Link to comment https://forums.phpfreaks.com/topic/113873-solved-refresh-checkboxes-form/#findComment-592295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.