Hi All,
I only read this list sporadically, so apologies if this question has
already been asked & answered.
This situation:
I'm using oohforms to generate forms dynamically from metadata values in a
database. For example, if the metadata says "radio," the script generates a
radio button. QED.
I'm using "radio" as an option to generate multiple mutually-exclusive
values in a control array. The code looks something like this:
//$answers is an array of
//$form is the form object variable
foreach($answers as $key=>$value) {
$form->add_element(array("name"=>"question",
"type"=>"radio",
"multiple"=>TRUE,
"value"=>$answers[$key]));
}
Later on I use the same loop to call $form->show_element("question",
$answers[$key]), so the final HTML for one set of controls looks something
like so:
<input type='radio' name='question' value='1'> Answer #1
<input type='radio' name='question' value='2'> Answer #2
<input type='radio' name='question' value='3'> Answer #3
<input type='radio' name='question' value='4'> Answer #4
The problem:
I'd like for nothing to be selected by default (i.e. the user chooses not to
answer the question at all). But for some reason, oohforms sets the last
rendered control to 'checked'. I though at first it may have something to do
with passing $value in the call to show_element, but if that were the case,
'checked' would be output for every control.
Any ideas on what I'm doing wrong? I'm doing something similar with
checkboxes without a hitch.
TIA,
Derek
|