grizzley — 2013-02-06T15:45:21-05:00 — #1
How do I set a checkbox element which is already checked in quickform2?
cups — 2013-02-07T09:42:52-05:00 — #2
Docs suggest it goes in as $data array, though I cannot confirm as I have not tested it.
This post I found then suggests you have to implicitly tell is to be checked, using chaining, beware though the Q was posed with Quickform and not Quickform2 - so may not applicable.
Like I say, all rather much guesswork, but I'm quite interested by QF2.
Ah, yes - confirmation and a link to the correct part of the api docs.
grizzley — 2013-02-07T15:41:34-05:00 — #3
Spent ages with this and nothing seems to work. I can set the value in $data array but the checkbox remains unchecked.
Web searches suggest this
$promos = $fieldset->addElement('checkbox', 'promos', array('value' => '6', 'checked' => 'checked'), array('label' => 'I would like to receive emails'));
but it still doesn't check the box.
Think its time for an alternative approach. Anybody able to recommend an alternative to quickform which will allow me to set rules and validate the form in a similar manner but without these problems?
cups — 2013-02-08T07:18:46-05:00 — #4
So did you try the solution I posted for you?
append (chain) this method:
[your declaration and then]->setChecked(true);
// maybe if I show you exactly
$promos = $fieldset->addElement('checkbox', 'promos',
array('value' => '6', 'checked' => 'checked'),
array('label' => 'I would like to receive emails'))->setChecked(true);
grizzley — 2013-02-08T11:02:33-05:00 — #5
Yes, tried that and it returns an error
Fatal error: Call to undefined method HTML_QuickForm2_Element_InputCheckbox::setChecked()
Cant figure this out as I have
at the top of the page so would have expected it to have found it.
I have also tried instantiating and echo a new object
$checkbox = new HTML_QuickForm2_Element_InputCheckbox(null, null, array('checked' => 'checked'));
This returns the checkbox but it is still unchecked.
Any thoughts appreciated.
cups — 2013-02-08T14:16:45-05:00 — #6
Sorry mate, I'm out of ideas and I just don't have the time to download this and test it for you.
grizzley — 2013-02-08T16:21:22-05:00 — #7
At last this seems to be getting close to what I want giving achecked box with value 6
$checkbox = new HTML_QuickForm2_Element_InputCheckbox('promos', array('checked' => 'checked', 'value' => '6'));
Cups, I appreciate what you say about not having time.....
Spent too long on this myself.