[FX.php List] Checkbox

Derrick Fogle derrick at fogles.net
Tue Apr 4 12:37:05 MDT 2006


The foreach() loop operating on the value list is working correctly,  
right? You get one checkbox for each value in the value list?

I've never seen the selected/checked value placed in quotes before;  
what happens if you do the selected output without being in quotes  
(but make sure there's a space after the closing quote for the value  
parameter)?

Also, I would drop the third argument from the in_array() function;  
it only serves to make the comparison a strict "type-alike" match.  
Remember, too, that everything is case sensitive, although the code  
looks like it should be comparing like-cased values.

The only other thing I can think of is the difference in the way the  
value list and the actual values are formatted. The value list has  
different separators than the actual field with the checked values, I  
think. The field with checked values should have each value separated  
by a return (\r), while the value list itself is an actual array, not  
a single field with some arbitrary separation character.

OK, my brain is empty now. Sorry I can't be more specific with my  
suggestions, but I hope this at least helps the debugging process.


On Apr 4, 2006, at 12:52 PM, Rob H. Christensen wrote:

> 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
>
>
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list


Derrick Fogle
derrick at fogles.net





More information about the FX.php_List mailing list