Re: HTML_QuickForm, advcheckbox, setChecked()

From: Date: Sat, 17 Apr 2004 19:30:10 +0000
Subject: Re: HTML_QuickForm, advcheckbox, setChecked()
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-27878@lists.php.net to get a copy of this message
On Apr 17, 2004, at 2:14 PM, Paul M Jones wrote:
On Apr 17, 2004, at 1:17 PM, Bertrand Mansion wrote:
I instantiate an advanced checkbox element... $element =& HTML_QuickForm::createElement( 'advcheckbox', $elemname, // element name $col['qf_label'], // label null, $col['qf_attrs'], // html attributes $col['qf_vals'] // array(unchecked, checked) ); ... and then attempt to set it as checked ... $element->setChecked(true);
This would work with a normal checkbox but not with the advanced checkbox. You should use $element->setValue() instead or set the default value with $form->setDefaults().
$form->setDefaults() is probably not going to do it for me; I'm building it element-by-element. So it would have to be $element->setValue(1)... ... and that doesn't do it either. _attributes['value'] is 1, and ['checked'] is 'checked'. The hidden field is named "edit[comments]" and the javascripted checkbox is named "__edit[comments]", but it's not set as checked. Hm. Sorry to be dumb. :-( What could I be doing wrong here?
Replying to self. Here's a test script, showing what doesn't work for me. <?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); ?> Shows the checkbox as not-checked, even though setValue() is 1. If you change the element type from 'advcheckbox' to 'checkbox' then it works fine. Is this a bug? -- Paul M. Jones pmjones@ciaweb.net Savant: the simple alternative to Smarty. http://phpsavant.com/

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