Determining submitted checkbox values in QuickForm
| From: | Skyler Slade | Date: | Wed, 18 May 2005 16:27:48 +0000 |
| Subject: | Determining submitted checkbox values in QuickForm | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-19261@lists.php.net to get a copy of this message | ||
Hi all,
I've run into some confusion on handling checkbox elements in
QuickForm. It is rather easy to create a list of checkboxes by using a
standard loop around an SQL query, however during the form processing,
I'm having difficulty determining which checkboxes were checked.
Using the standard QuickForm 'checkbox' element, the checkbox values
are always 1, and they cannot be changed. If one was to write a form
such as this using HTML (instead of using the QuickForm class) finding
out which checkboxes were checked would be relatively easy. If I were
to write it in HTML, all of the checkboxes name's would be an array,
such as array[], and the values for the checkboxes would be whatever I
would give them. After form submission and during processing, I simply
create a loop around $_POST['array'], and foreach value in array[], I
do _something_ with the value. This makes it very easy to insert only
selected items into a database.
As valuable a feature as this would be (the ability to change checkbox
values), it does not appear to be implemented so far as I can tell. In
this case, how would one determine and parse which checkboxes were
checked? As is, if I loop through the array of the checkbox names
(using array[] for their names when creating them) I receive multiple
values of 1, which isn't very helpful for determining which checkbox
they belong to. There is a method called "getChecked()," would this be
used? I realize that 'advcheckbox' may be able to help with this, but
it seems too much like a complex solution to a simple problem, as I'd
rather not introduce JavaScript into this form for various reasons.
Any help would be much appreciated.
Thanks again,
-Skyler