Quickform2 checkboxes
| From: | Alain Williams | Date: | Wed, 18 Nov 2009 23:49:47 +0000 |
| Subject: | Quickform2 checkboxes | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-30153@lists.php.net to get a copy of this message | ||
Trying to get to use checkboxes with quickform2.
A checkbox can be given more than once in a form with the same name:
http://www.w3.org/TR/html401/interact/forms.html#checkbox
If you do this you only see the value of the last one set in the form.
OK: set as an array name, eg:
$form->addElement('checkbox', 'vegetable[]', array('value' =>
1), array('label' => 'carrot'));
$form->addElement('checkbox', 'vegetable[]', array('value' =>
2), array('label' => 'pea'));
$form->addElement('checkbox', 'vegetable[]', array('value' =>
3), array('label' => 'bean'));
PHP correctly interprets that resulting in the following in an array if carrot & bean are
selected:
[0] => 1
[1] => 3
However, this does not appear in what $form->getValue() returns.
I could give them separate names as below -- but that makes processing harder:
$form->addElement('checkbox', 'vegetable1', array('value' =>
1), array('label' => 'carrot'));
$form->addElement('checkbox', 'vegetable2', array('value' =>
2), array('label' => 'pea'));
$form->addElement('checkbox', 'vegetable3', array('value' =>
3), array('label' => 'bean'));
How am I supposed to do this ?
--
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
Past chairman of UKUUG: http://www.ukuug.org/
#include <std_disclaimer.h>