Zend Framework Custom Validation Class Error Message
Posted
by remlabm
on Stack Overflow
See other posts from Stack Overflow
or by remlabm
Published on 2010-04-29T17:42:36Z
Indexed on
2010/04/29
17:47 UTC
Read the original article
Hit count: 261
The validation fails as it should but does not return the 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 fails does not give the "IN_USE" error.
© Stack Overflow or respective owner