Jump to content

[SOLVED] sticky checkboxes


nomis

Recommended Posts

Hi, I'm sorry if this has been answered elsewhere, but I'm having some trouble keeping some checkboxes that were called as an array to stay sticky if the form errs on other required fields.

 

Here's what I have have:

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width=500 border=0 cellpadding=5>
<tr>
<td valign="top"><label for "person_type_code">Person Type:</label> </td>
<td><?php 
$r = mysqli_query($dbc, 'select * from person_type order by person_type');
while ($row = mysqli_fetch_array($r)) {
echo '<input type="checkbox" id="person_type" name="person_type_code[]" ' ;
echo 'value="' . $row[0] .'"';
    if (isset($_POST['person_type_code'])) { echo ' checked="checked"';
	} 
    echo '> ' . $row[1] . '<br />'; 
}
?> </td> 

 

This is unfortunately making EVERY checkbox show as checked, not just the ones that the user has selected.  I need this form to come back with only the fields that a person has selected (one or more... a person may have many types) to appear checked.

 

Can someone see what is wrong with my code?  I have tried using  $row in place of $_POST['person_type_code'] but it has the same effect. 

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/169296-solved-sticky-checkboxes/
Share on other sites

  • 2 years later...

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.