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') {
+
     if ($vars['email'] != 'test') { // perform some validation
 
         /* @var $email HTML_QuickForm2_Element */
 
         /* @var $email HTML_QuickForm2_Element */
 
         list($email, ) = $form->getElementsByName('email');
 
         list($email, ) = $form->getElementsByName('email');

Revision as of 02:41, 10 January 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 ($vars['email'] != 'test') { // perform some validation
        /* @var $email HTML_QuickForm2_Element */
        list($email, ) = $form->getElementsByName('email');
        $email->setError('Some Error Accured!');
    }
}