Re: Trying to validate a form using QuickForm

From: Date: Fri, 08 Jul 2005 17:17:05 +0000
Subject: Re: Trying to validate a form using QuickForm
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19918@lists.php.net to get a copy of this message
On 7/8/05, Gerard Bowe <gerard.bowe@jrc.it> wrote: > I have a form set up using QuickForm and everything's fine until I try > to access grouped items. > > For all individual elements, I have no problem, but when I try and use > grouped items I get a warning; > > I am doing it like this > > ....... > > $form->addElement('text', 'status', 'Status: '); > $form->addElement('text', 'usregroup', 'User Group: '); > > $group[] =& HTML_QuickForm::createElement('text', 'first', 'First > Name'); > $group[] =& HTML_QuickForm::createElement('text', 'last', 'Last > Name'); > > $form->addGroup($group, 'name', 'Name:', ',&nbsp;'); > > ..... > > echo htmlspecialchars($form->exportValue('name')); > > Warning: htmlspecialchars() expects parameter 1 to be string, array given > > I guess it's because grouped items are passed as an array, but I'm not > sure how to access them so as to further process them. > > > > I want to pass each value to a DB_DataObject, like > > $staff = new DataObject_Staff(); > > > $staff->first = htmlspecialchars($form->exportValue('first')); > > ........ > > Don't know if this is the right way to do it? > You can try: $staff->first = $form->exportValue('name[first]'); although I don't know if that works. You can also try: $name = $form->exportValue('name'); $staff->first = $name['first']; $staff->last = $name['last']; Or you can just use exportValues and not have to exportValue every single element with another function call. $values = $form->exportValues(); $staff->first = $values['name']['first']; $staff->last = $values['name']['last']; $staff->status = $values['status']; and so on -- Justin Patrin

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