Re: Quickform group error

From: Date: Fri, 08 Dec 2006 13:11:49 +0000
Subject: Re: Quickform group error
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26027@lists.php.net to get a copy of this message
Hi, rav k wrote:
Do you mean clear the skills array in the while loop before adding the next one???
No, I mean doing $skills = array(); before the while loop.
Also can you explain why the error is caused in this case so we can troubleshoot this ourselves in the future :)
If you have register_globals on (which *is* deprecated for quite a bit of time) then after the form submit you have a $skills array containing the submit values of your group. And then you append form elements to this array in your while loop. Then the group element iterates over its children expecting them to be instances of HTML_QuickForm_element and you get your "Call to a member function on a non-object" error.
This is what I'm doin to dynamically add the skills as checkboxes: /* ADD THE SKILLS */ $res =& $mdb2->query('SELECT * FROM Skills'); while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
    $skills[] = &HTML_QuickForm::createElement('advcheckbox', $row['skillid'], null,'<b>'.$row['skillname'].'</b>'.' : '.$row['description']);
} And I am adding them this way: $form->addGroup($skills, 'skills', 'Your skills:', '<br />'); The problem is I get the following error when attempting to validate: Fatal error: Call to a member function on a non-object in /home/user/public_html/iim/pear/PEAR/HTML/QuickForm/group.php on line 391 Can anyone please offer a solution to this??
Turn off register_globals and/or clear the $skills array before adding form elements to it.


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