驗證失敗,因爲它應該但不返回錯誤消息。Zend Framework自定義驗證類錯誤消息
$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'),
),
));
自定義類:
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;
}
}
只是失敗並沒有給 「IN_USE」 的錯誤。
可否請你指出的區別? – 2012-12-17 00:05:47