[FX.php List] Checkbox

Rob H. Christensen robhelleshoj at tiscali.dk
Tue Apr 4 11:52:01 MDT 2006


I can see, that I am not the only one who runs into problems here.

My original solution to show the data from FM wads taken from "FX.php in 8
hours" (page 49) 

<?php
$state_value=$findData['state'][0];
foreach($listsResult['valueLists']['state'] as $key=>$value){
if($state_value==$value){
$selected="checked";
}else{
$selected="";
}
?>
<input type="checkbox" name="state" value="<?php echo $value;
?>"<?php echo $selected; ?>><?php echo $value; ?>
<?php
}
?>


That is the same as the one for radio buttons on the previous page just with
the word radio changed to checkbox.

It does not work.

Then I gave it a thought, looked up the definitions for checkboxes and found
out, I had to do something else.
I tried

<?PHP
$TRK=$Data['Trykkeri'][0];
foreach($Vis2ListResult['valueLists']['Trykkeri'] as $key=>$value){
            if($TRK==$value){ $Select="checked";}else{$Select="";} ?>
            <input type="checkbox" name="Trykkeri" value="<?PHP echo $value;
?>""<?PHP echo $Select;?>"><?PHP echo $value;
            }?>

Does not work

I modified this in several steps ending up with:


<?PHP
$TRK=$Data['Trykkeri'][0];
$TRK2=list(",",$TRK
foreach($Vis2ListResult['valueLists']['Trykkeri'] as $key=>$value){
if(in_array($value,$TRK2,true){$Select="checked";}else{$Select="";} ?>
            <input type="checkbox" name="Trykkeri" value="<?PHP echo $value;
?>""<?PHP echo $Select;?>"><?PHP echo $value;
            }?>

It does not work. 

The point is, as long as there is but one out of five checkboxes checked, it
works. But as soon as more then one is checked (and that is what checkboxes
are for) it does not work.

Somehow the data coming from FileMaker is not what I think it is. If I
display the array in the page (print_r), it contains  the names of the
checked boxes in $Data['Trykkeri'][0] like Kniv010 and 4F014, when I spilt
the array later on, it suddenly contained until several more of this kind,
mirroring my experiments with the names of the checkboxes (the valuelist in
FMP)


Now, how do I compare the content of $Data['Trykkeri'] with the content of
the valuelist, in order to check the boxes on the webpage?

Allyson, 

Your solution:

<?php foreach($Vis2ListResult['valueLists']['Trykkeri'] as $key=>$value){ ?>

    <input type="checkbox" name="Trykkeri" value="<?php echo $value; ?>"
<?php if(in_array($value, $Data['Trykkeri'][0])) echo '"checked"'; ?> />
    <?php echo $value; } ?>


Works only for one box checked not for more, just as the one you wrote in
"FX.php in 8 hours"

> Note however that this is also going to result in you losing data when this
> is posted back to the db because you're using the name 'Trykkeri' for each
> of the check boxes, so whichever is the last checkbox selected is what that
> variable will enter when posted back to the db.

In FileMaker (6 at least) the checkbox is a valuelist with one name and a
field with one name (I use the same name in both cases) set as a checkbox
taking its values from the valuelist.

If I understand you correct in html you want a different name for each value
in the checkbox.  I did not come so far as to edit FileMaker from this
particular page yet , so I am wondering. The difenitions about checkboxes
say, that several of them can have the same name:

(definitions from GoLive)
"Several checkboxes in a form may share the same control name. Thus, for
example, checkboxes allow users to select several values for the same
property. The INPUT element is used to create a checkbox control."

Rob
 




More information about the FX.php_List mailing list