PHP 5.1.2
Apache 2.x
On a RedHat box
OK, I've been trying to nail down a solution to this problem for about 3 days now and nothing I've tried seems to work. I'm creating a survey and want to ask a question and have the user select only 1 answer. Obviously this should be done with a radio button group.
To minimize code, I created an array with the potential answers to the questions then wanted to loop through that array to generate each call for the radio button. Below is my code, then the error I receive after submitting the form.
The error I get is:PHP Code:$form = new HTML_QuickForm("edwards");
//Question 2
$form->addElement('html', '<tr><td> </td></tr><tr><td colspan="2"><h4>2. What was your main reason for continuing your education? (Choose one.)</h4></td></tr>');
$q2_values = array('Advance my career',
'Career change',
'Personal fulfillment');
foreach($q2_values as $key=>$val) {
//Line 31 below
$q2[$key] = &HTML_QuickForm::createElement('radio',
null, // name for radio button, assigned by group
' ', // text to display before button
$val.'<br />', // text to display after button
//Line 35 below
$val); // the value returned
}
$form->addGroup($q2,'q2','',' ');
$form->addElement('text', 'q2_text', '<input type="radio" name="q2" value="Other" /> Other:', array('size'=>40));
$form->addRule('q2', 'You must answer Question 2.', 'required', '', 'client');
//Submit button
$form->addElement('submit', 'submitted', 'Submit Survey');
//Process/Display
if ($form->validate()) {
echo 'Form validated!<p>';
$form->process('process_survey');
} else {
//echo 'Form not yet valid!<p>';
$form->display();
}
Fatal error: Cannot create references to/from string offsets nor overloaded objects in /apps/home/edwards/public_html/cgi-bin/survey2007/survey2.shtml on line 35
A colleague suggested making it without the ampersand : $q2[$key] = HTML_QuickForm::createElement
Which instead throws the error: Catchable fatal error: Object of class HTML_QuickForm_radio could not be converted to string in /apps/home/edwards/public_html/cgi-bin/survey2007/survey2.shtml on line 31
Can I accomplish this without hard-coding each radio button? Thanks for any help you all can provide.







Bookmarks