checkbox problem (php)

Soldato
Joined
4 Jul 2004
Posts
2,647
Location
aberdeen
Hello
I have the following in a form, that gets submitted to another page:
Code:
<input type="checkbox" name="oursite" value="1" />
<input type="checkbox" name="oursite" value="2" />
... and so on, till
<input type="checkbox" name="oursite" value="13" />
But when i do:
PHP:
$oursite = strip_tags($_POST['oursite']);
echo $oursite;
Everytime i get "13", even if #13 isn't ticked, or if more than one is ticked etc.

:S
 
To further iterate what Inquisitor has said; because checkboxes allow for multiple selections a unique name is required for each checkbox which when retieved gives a boolean (true/false) return.

You need to decide whether it is neccesary to have multiple sections.
 
you don't need a unique name:

Code:
<input type="checkbox" name="oursite[]" value="1" />
...
<input type="checkbox" name="oursite[]" value="13" />

php:
Code:
<?php

foreach ($_POST['oursite'] as $box) {
    echo $box . "<br />\n";
}

?>
 
Back
Top Bottom