QuickForm checkboxes and their return values
| From: | Mitch Anderson | Date: | Fri, 19 Nov 2004 19:03:11 +0000 |
| Subject: | QuickForm checkboxes and their return values | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-15697@lists.php.net to get a copy of this message | ||
I'm running into problems in using quickform... I'm trying to
figure out how I check to know if the checkbox was checked. The problem
I'm having is, depending on the data in the database, the check should
be checked already. However, If I remove the check and submit...
exportValue is still sending a 1... If its not checked in
the DB, and I check it, and submit, it works fine. Or if its not
checked and I submit it unchecked, it comes through as being
unchecked. I've been trying to find an example of how someone else was
using it and reading through pear.php.net[1] hasn't shed any more light
on things either... A sample of my code is below. What am I doing
wrong?
// $data_array holds result of one row from a database.
$data_array = $data_result->fetchRow(DB_FETCHMODE_ASSOC);
$form = new HTML_QuickForm('Form');
$checked =& $form->addElement('checkbox', 'check1', NULL,
'CheckMe',
null);
if($data_array['check1'] == 1) { $checked->setChecked(true); }
$form->addElement('submit', null, 'Submit');
if($form->validate()){
$checked = $form->exportValue('check1');
if($checked){
$ret_array['check1'] = 1;
} else {
$ret_array['check1'] = 0;
}
} else {
$form->display();
}
[1] http://pear.php.net/manual/en/package.html.html-quickform.html-
quickform-checkbox.html-quickform-checkbox.php
Mitch