|
Posted by Sonnich on 08/08/06 12:46
Rik wrote:
> 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)?
That was meant as debugging :-)
>
> > ."</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:
Almost.
In case of any new items, they should be checked too.
There are other options, which might change sql query and by that the
array, so we have new items. They should be selected by default when
they appear.
Otherwise I found this useful.
I'll have to read a bit more about this subjet for PHP.
BR & thanks
Sonnich
>
> 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]
|