Nested forms and validate each form
| From: | Mark Steudel | Date: | Sun, 12 Feb 2006 03:18:26 +0000 |
| Subject: | Nested forms and validate each form | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-22940@lists.php.net to get a copy of this message | ||
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?
$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();
}