Difference between revisions of "How to add special validation for some fields on signup form"

From aMember Pro Documentation
Jump to: navigation, search
Line 9: Line 9:
 
     $form = $event->getForm();
 
     $form = $event->getForm();
 
     $vars = $form->getValue();
 
     $vars = $form->getValue();
     if ($vars['email'] != 'test') { // perform some validation
+
     if (isset($vars['email']) && ($vars['email'] != 'test')) { // perform some validation
         /* @var $email HTML_QuickForm2_Element */
+
         $event->addError('Some Error Accured!');
        list($email, ) = $form->getElementsByName('email');
+
        $email->setError('Some Error Accured!');
+
 
     }
 
     }
 
}
 
}
 
</source>
 
</source>

Revision as of 02:25, 24 June 2013

Create /amember/application/configs/site.php with this code:

<?php
Am_Di::getInstance()->hook->add(Am_Event::VALIDATE_SAVED_FORM, 'siteValidateForm');
 
function siteValidateForm(Am_Event_ValidateSavedForm $event)
{
    $form = $event->getForm();
    $vars = $form->getValue();
    if (isset($vars['email']) && ($vars['email'] != 'test')) { // perform some validation
        $event->addError('Some Error Accured!');
    }
}