Re: QF Checkbox value setting

From: Date: Fri, 24 Oct 2003 13:32:59 +0000
Subject: Re: QF Checkbox value setting
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-8558@lists.php.net to get a copy of this message
Mike Carter wrote:
Hi, In a bit of a confuddle with setting a more unique value for when a checkbox is selected on a quickform. Using: $this->addElement('checkbox', $key, $language['L_'.ucfirst($value)], '')); I get: <input name="1GZc" type="checkbox" value="1" id="qf_fcfe58" /> If I then try to force set a value using: $this->addElement('checkbox', $key, $language['L_'.ucfirst($value)], '', array('value' => 'arse')); I get: <input value="1" name="1GZc" type="checkbox" id="qf_fa141d" /> Why is my value not set to 'arse' ? Something is over riding it to '1' still? Is this a bug? The quickform checkbox element can only have a boolean value. It's either set or not. I had the same problem.
Two things you can do IIRC: 1. use advcheckbox 2. put the value in the name of the checkbox. If you have a checkbox that looks like this <input type="checkbox" name="mycheckboxes[arse]" /> it will work. when processing the results you do: foreach ($_POST['mycheckboxes'] as $key => $value) { this will print a filthy word :'. $key . '<br />'; } if you have only one checkbox you don't need the loop ofcourse, but in most situation you'll have more than one because if you just have one you don't need a value you just need a name and whether it was checked or not. HTH Jeroen

« previous php.pear.general (#8558) next »