Zend Framework Authentication Class Error Message

Validation fails, as it should, but does not return an error message.

$form->addElement('text', 'phone_number', array( 'required' => true, 'validators' => array( array('NotEmpty', true, array('messages' => 'Enter a valid Phone Number')), array('regex', false, array('pattern' => '/\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}/', 'messages' => 'Enter a valid Phone Number' )), 'CheckPhoneNumber'), ), )); 

Custom class:

 class Custom_Validators_CheckPhoneNumber extends Zend_Validate_Abstract{ const IN_USE = 'inUse'; protected $_messageTemplates = array( self::IN_USE => "'%value%' is currently in use" ); public function isValid($value) { $this->_setValue($value); $user_check = Users::getActive(preg_replace("/[^0-9]/", "", $value)); if($user_check->id){ $this->_error(self::IN_USE); return false; } return true; } 

}

Just a crash does not give the error "IN_USE".

+1
source share
3 answers

Is this just a phone_number element that doesn't display errors or are there others?

Have you disabled the default decorators with disableLoadDefaultDecorators ?

How about providing a custom validator in an array:

 $form->addElement( 'text', 'phone_number', array( 'required' => true, 'validators' => array( array( 'NotEmpty', true, array( 'messages' => 'Enter a valid Phone Number' ) ), array( 'regex', false, array( 'pattern' => '/\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}/', 'messages' => 'Enter a valid Phone Number' ) ), array( 'CheckPhoneNumber' ) ) ) ); 
+2
source

Are you sure the failure in your custom validator? Try to make sure that it really does not work in the custom validator.

If not, verify the prefix path for the form elements is correct.

 $form->addElementPrefixPath( 'Custom_Validators', 'Custom/Validators', 'validate' ); 

The code for the custom validator looks fine.

+1
source
  $form->addElement('text', 'phone_number', array( 'required' => true, 'validators' => array( array('NotEmpty', true, array('messages' => 'Enter a valid Phone Number')), array('regex', false, array('pattern' => '/\([0-9]{3}\)\s[0-9]{3}-[0-9]{4}/', 'messages'=>array(Zend_Validate_Regex::NOT_MATCH=>'%value% is not a valid phone') )), 'CheckPhoneNumber'), ), )); 
+1
source

Source: https://habr.com/ru/post/923913/


All Articles