Re: Nested forms and validate each form
| From: | Justin Patrin | Date: | Sun, 12 Feb 2006 07:29:56 +0000 |
| Subject: | Re: Nested forms and validate each form | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-22941@lists.php.net to get a copy of this message | ||
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