Re: QF: checkbox element

From: Date: Mon, 20 Oct 2003 11:07:24 +0000
Subject: Re: QF: checkbox element
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-8494@lists.php.net to get a copy of this message
<mikeatwork@ukonline.co.uk> wrote : > Hi, > > I'm trying to work out how to change the value attribute which is returned > when a checkbox is "checked". > > I look through an array of checkbox values and names, > $problems = array('123' => 'angina', '456' => > 'heartattack', '789' => > 'ischaemic', '321' => 'stroke'); etc... > > foreach($problems as $key => $value){ > $this->addElement('checkbox', $key, $value, null); > } > > $value is the label and $key is the number I would like to return if the > checkbox is ticked. > > The generated HTML is: > <input name="123" type="checkbox" value="1" > id="qf_be76e4" /><label > for="qf_be76e4"></label> > > However the values being stored in the quickform controller container are: > [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) > "1" > > The above array key is going up numerically, so how does it know which > checkbox should be checked? Should the array key not be linked to the input > s "name" attribute? Ie ["123"] => string(1) "1" ? > > Also note that I set the checkboxes label to null, yet in the HTML I still > get the <label></label> tags; is there a way to prevent this additional mess > in the HTML code? > > I checked through the QF checkbox.php code, and also had a peek at the > advanced checkbox, but couldn't see an immediate solution to either of my > problems. > > Any ideas? This is probably related to the way array_merge works. If your keys are numeric, they will be reordered starting at index 0. I don't like this behaviour neither but it seems there's nothing we can do about it and that's the way it's expected to work :( You could solve this by prefixing your problems code with a letter in order to make array_merge understand it's a string. Bertrand Mansion Mamasam

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