[UPHPU] QuickForm and Checkboxes, is it checked?

TJ Hunter tjhunter at ruistech.com
Fri Nov 19 09:54:20 MST 2004


    function is_checked($var)
    {
        if ((strtoupper($var) == 'ON' ) || ( $var == 1 ) || ( $var == 
TRUE ))
        {
            return(1);
        }
        else
        {
            return(0);
        }
    }


Mitch Anderson wrote:

>I'm running into problems in using quickform... I'm just 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... I'm
>still seeing it as being checked in my validate... If its not check 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 still 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 == 1){
>		$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
>
>  
>




More information about the UPHPU mailing list