Check Box Layout and Validation
Posted: Thu Sep 28, 2006 5:47 am
Hi, I was wodering if anyone can help me with a problem I am having with validating mulitple values from a series of checkboxes.
This is my form at the moment:
and the submit code, which at the moment is only submitting a single value, though as many as four can be checked:
tblUrlcity contains these values:
1 London
2 New York
3 Miami
4 Bristol
Also is there any way to sort the retrieved checkboxes so that after 4 column of data, the next checkbox falls under a new <tr>?
I would appreicate any help given.
Thank you in advance
This is my form at the moment:
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
echo '<table><tr>';
$query = "SELECT cityID, city FROM tblUrlcity ORDER BY city ASC";
$result = mysql_query ($query);
while($row = mysql_fetch_array ($result, MYSQL_NUM)) {
extract($row);
echo '<td><input type="checkbox" class="formstyle" name="cinterests[]" value="' ,$row[0], '">' ,$row[1], '</td>';
}
echo '</tr>';
echo '<tr><td><input type="submit" value="SELECT" class="button"/></td></tr></table>';
?>
</form>Code: Select all
// city interests
if (isset($_POST['cinterests'])) {
$cintr = NULL;
foreach ($_POST['cinterests'] as $key
=> $value) {
$cintr .= "$value, ";
}
$cintr = substr($cintr, 0, -2); //cut off the last comma-space.
$cint = TRUE;
}else{
$cint = NULL;
$message .= '<p>You forgot to enter your city interest(s).</p>';
}1 London
2 New York
3 Miami
4 Bristol
Also is there any way to sort the retrieved checkboxes so that after 4 column of data, the next checkbox falls under a new <tr>?
I would appreicate any help given.
Thank you in advance