RE: [PEAR] Nested forms and validate each form

From: Date: Sun, 12 Feb 2006 20:00:56 +0000
Subject: RE: [PEAR] Nested forms and validate each form
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-22944@lists.php.net to get a copy of this message
Thanks Justin, Since I wanted the first form to think it was validated I didn't' change that one. I changed the userForm to: $userForm = new HTML_QuickForm('userForm', 'post', null, null, null, true); It still just passes through even if I leave all the fields blank. I thought perhaps it was the array variables, so I made another test field: $userForm->addElement( 'text', 'test', 'First name:' ); $userForm->addRule('test', 'Your email is required.', 'required'); And left it blank, but it still validated ... Thanks, Mark -----Original Message----- From: Justin Patrin [mailto:papercrane@gmail.com] Sent: Saturday, February 11, 2006 11:30 PM To: Mark Steudel Cc: pear-general@lists.php.net Subject: Re: [PEAR] Nested forms and validate each form On 2/11/06, Mark Steudel <mark@netriver.net> wrote: > I've got the following form, and Im having problems getting the second > form to stop on incorrect validation. Can I do something like this? > Use the "trackSubmit" constructor parameter (pass true). > $form = new HTML_QuickForm('Add Group', 'post', > 'addGroup.php?action=add'); > > if( $form->validate() ) > { > $userForm = new HTML_QuickForm('User form'); > $userForm->registerRule('checkAddEmail', 'function', > 'checkDuplicateAdditionalEmail'); > $userForm->addElement( 'hidden', 'action', 'add' ); > > if( $userForm->validate()) > { > > // save data > } > else > { > for( $i = 0; $i < $_POST['numaccounts']; $i++ ) > { > > $userForm->addElement( 'text', 'user['.$i.'][fname]', > 'First name:' ); > $userForm->addElement( 'text', 'user['.$i.'][lname]', > 'Last name:' ); > $userForm->addElement( 'text', 'user['.$i.'][email]', > 'Email:' ); > $userForm->addRule('user['.$i.'][email]', 'Your email is > required.', 'required'); > } > > $userForm->addElement( 'submit', 'infosubmit', 'Submit: ' > ); > > $html .= $userForm->toHtml(); > } > } > else > { > > $form->addElement( 'select', 'numaccounts', 'Choose Number of > Accounts: > ', $numGroups ); > $form->addElement( 'submit', 'submit', 'Submit: ' ); > > $html .= $form->toHtml(); > > } > > -- > PEAR General Mailing List (http://pear.php.net/) To unsubscribe, > visit: http://www.php.net/unsub.php > > -- Justin Patrin

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