Re: More issues with QF/QFC

From: Date: Fri, 09 Jan 2004 08:36:02 +0000
Subject: Re: More issues with QF/QFC
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-10074@lists.php.net to get a copy of this message
<barry@hpfm.biz> wrote : > Hi, > I managed to fix the issue with defaults - essentially I had to build > the array of default values rather than use setValue, after any submit. > > I now have a more problemsome issue. I have a form that build a list of > checkbox options based on fields in reference tables (some of which > require explanations). Example html is below > > <html> > </tr> > <td valign='top'>Type of Incident<br>(may choose more > than > one) > <font color="red" size="1">*</font> > </td> > <td><input name="Type[1]" type="checkbox" > value="1" > id="qf_a39a15" /><label for="qf_a39a15">1|Major First > Aid</label><br ><input > name="Type[2]" type="checkbox" value="1" id="qf_92b107" > /><label > for="qf_92b107">2|Minor First Aid</label><br ><input > name="Type[3]" > type="checkbox" value="1" id="qf_da30e9" > checked="checked" /><label > for="qf_da30e9">3|Major Rescue</label><br ><input > name="Type[4]" > type="checkbox" value="1" id="qf_268e1c" > checked="checked" /><label > for="qf_268e1c">4|S & R</label><br ><input > name="Type[5]" type="checkbox" > value="1" id="qf_0299d6" checked="checked" /><label > for="qf_0299d6">5|Member > Injury</label><br ><input name="Type[6]" type="checkbox" > value="1" > id="qf_6f1868" /><label for="qf_6f1868">6|Employee > Injury</label><br ><input > name="Type[7]" type="checkbox" value="1" id="qf_274f4c" > /><label > for="qf_274f4c">7|Carnival Incident</label><br ><input > name="Type[8]" > type="checkbox" value="1" id="qf_862597" /><label > for="qf_862597">8|Complaint</label><br ><input > name="Type[9]" type="checkbox" > value="1" id="qf_cd2fd7" /><label > for="qf_cd2fd7">9|Drowning</label><br > ><input name="Type[10]" type="checkbox" value="1" > >id="qf_ac7ebf" /><label > for="qf_ac7ebf">10|Near Drowning</label><br ><input > name="Type[11]" > type="checkbox" value="1" id="qf_798402" /><label > for="qf_798402">11|Other</label><br ><input size="30" > name="Type[11Expl]" > type="text" value="" /></td> > </tr> > </html> > > > This create a nice list of options but if the user selects a set of > options (say 1,2,10,11) - $page->controller-exportValues() gives :- > > ["Type"]=> > array(5) { > [1]=> > string(1) "1" > [2]=> > string(1) "1" > [3]=> > string(1) "1" > [4]=> > string(1) "1" > ["11Expl"]=> > string(4) "Blah" > > I had expected > > ["Type"]=> > array(5) { > [1]=> > string(1) "1" > [2]=> > string(1) "1" > [10]=> > string(1) "1" > [11]=> > string(1) "1" > ["11Expl"]=> > string(4) "Blah" > > It seems to me that that it would be alot easier if I could simply set the > Value to > be returned (it defaults to '1'), that way I can simply read the value. > > I use :- > <code> > > function createCheckBoxGroup($elementName,$dbResult) > { > while ($row = $dbResult->fetchRow()) > { > //Var_Dump::display($row); > $DEGroup[] = & > HTML_QuickForm::createElement('checkbox',$row[1],null,$row[0]); > if ($row[2] == 'Y') > { > $explFieldName = $row[1].'Expl' ; > //echo "<hr>". $explFieldName; > $DEGroup[] = & > > HTML_QuickForm::createElement('text',$explFieldName,'','size=30'); > } > } > return $DEGroup; > } > </code> > > to build the options (there are about 8 of these on the page); > > Thanks in advance. This is due to array_merge() in exportValues(). Again, I'd like to curse the guy who wrote this rip-off array_merge() function. Last time I complained about this, I was told by some clever guy that this behavior is documented. So what, because it is documented doesn't mean it is not stupid. Anyway, we will probably have to write our own for QuickForm because array_merge() reorders your keys when your keys are numbers, even if they actually are strings because you used quotes. Very clever isn't it ? Array_merge() is not only a function that will merge two arrays into one, as the name states, but it is also a filter that will convert strings to numbers! How cool ! Is this not an example of BAD design ? Now, about your other problem, checkboxes in QuickForm only return 1 when they are checked so you know that they are checked. You can use advcheckbox for a more complicated behavior. Bertrand Mansion Mamasam

« previous php.pear.general (#10074) next »