Re: HTML_QuickForm, advcheckbox, setChecked()

From: Date: Sun, 18 Apr 2004 03:51:27 +0000
Subject: Re: HTML_QuickForm, advcheckbox, setChecked()
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-27901@lists.php.net to get a copy of this message
-----quote----- In the past, when I have needed behavior similar to the advanced checkbox, I have used a dual hidden + checkbox approach, instead of a JavaScript approach. For example... <input type="hidden" name="my_checkbox" value="not-checked" /> <input type="checkbox" name="my_checkbox" value="checked" /> ... so that the 'not-checked' value comes back if the box is not checked, and if it is, the 'checked' value comes back instead (it overrides the earlier value). Is this a valid and standards-compatible approach? I ask only because HTML_QuickForm might be able to make use of it, instead of the JavaScript, thus tightening things up just a little bit. Just asking about practices; not a critique, the current behavior is just fine. ----- end quote ------- This seems a wacky thing to do, it's definitly not standards compatible - two elements may not have the same name. With checkboxes, to make a box checked it's: <input ... checked="checked" /> Not checked is: <input .. />. The use of value="not-checked" is completely invalid. The use of value="checked" doesn't work for me in firefox. The way I (and you may have a reason this won't work for you) test the value of a checkbox is as follows: if ($_POST['checkbox'] == "on") $value = true; else $value = false; What is wrong with this simple approach? "Paul M Jones" <pmjones@ciaweb.net> wrote in message news:C5B34310-90CE-11D8-9B84-003065A2510C@ciaweb.net... On Apr 17, 2004, at 5:25 PM, Bertrand Mansion wrote: > <pmjones@ciaweb.net> wrote : > >> <?php >> >> require_once 'HTML/QuickForm.php'; >> require_once 'Var_Dump.php'; >> >> $elem =& HTML_QuickForm::createElement( >> 'advcheckbox', >> 'xbox', >> 'Label:', >> null, >> null, >> array(0,1) >> ); >> >> $elem->setValue(1); >> >> Var_Dump::display($elem); >> >> $form =& new HTML_QuickForm(); >> $form->addElement($elem); >> $form->display(); >> >> Var_Dump::display($form); >> >> ?> > > Thanks for the test case. > Looks like line 250 of advcheckbox.php should read: > > if (null !== $value) { > $this->setValue($value); > } > > Could you please test and file a bug :) Yes, that fixes it, will file a bug shortly. In the past, when I have needed behavior similar to the advanced checkbox, I have used a dual hidden + checkbox approach, instead of a JavaScript approach. For example... <input type="hidden" name="my_checkbox" value="not-checked" /> <input type="checkbox" name="my_checkbox" value="checked" /> ... so that the 'not-checked' value comes back if the box is not checked, and if it is, the 'checked' value comes back instead (it overrides the earlier value). Is this a valid and standards-compatible approach? I ask only because HTML_QuickForm might be able to make use of it, instead of the JavaScript, thus tightening things up just a little bit. Just asking about practices; not a critique, the current behavior is just fine. Thanks again for your quick responses. :-) -- Paul M. Jones pmjones@ciaweb.net Savant: the simple alternative to Smarty. http://phpsavant.com/

« previous php.pear.dev (#27901) next »