|
Posted by Rik on 08/07/06 20:32
Sonnich wrote:
> <?
> $part1[]="a";
> $part1[]="b";
> $part1[]="c";
> for($i=0; $i<count($part1); $i++)
> {
> echo "<td><input name=\"".$part1[$i]."\" type=\"checkbox\"
> value=\"true\"";
> if( !(isset($_POST[$part1[$i]])) && ($_POST[$part1[$i]] == "") )
> echo " checked";
> echo ">". isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]
Euhm, what it this last bit
'isset($_POST[$part1[$i]])."-".$_POST[$part1[$i]]' actually supposed to do?
It will either print '1-true' or ''(nothing)?
> ."</td></tr>";
> }
You've got a submit button, it's name is in the POST array, so it should be
present if the form is posted. Before posting, everything should be checked.
After the posting only the previously left checked values should be checked,
the rest unchecked. Is that how it should work? in that case:
So let's say checked when:
- $_POST['submit'] is not set
OR
- $_POST[$key] is in the array AND the value isn't empty
$part1 = array('a','b','c'...........
foreach($part1 as $value){
$checked = (!isset($_POST['submit'] || (isset($_POST[$value]) &&
!empty($_POST[$value])) ? ' checked' : '';
printf('<td><input type="checkbox" name="%1$s"
value="true"%2$s>%1$s</td>',$value,$checked');
}
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|