Jump to content

[SOLVED] refresh checkboxes form


Pavlos1316

Recommended Posts

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

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,

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.