Zend Framework Custom Validator on Form Elements -
hi trying set element custom validator in zend form have.
class siteanalysis_form_user_changepassword extends sa_form_abstract { public function init() { // add path custom validators $this->addelementprefixpath( 'siteanalysis_validate', application_path . '/modules/siteanalysis/models/validate/', 'validate' ); $this->addelement('text', 'passwdverify', array( 'filters' => array('stringtrim'), 'validators' => array('passwordverification',array('stringlength', true, array(6, 128))), 'decorators' => array('viewhelper','errors', array('htmltag', array('id' => 'passwdverify')), array('label', array('placement'=>'prepend','class'=>'label'))), 'required' => true, 'label' => 'confirmar contraseña nueva', )); $this->addelement('submit', 'change', array( 'label' => 'cambiar', 'required' => false, 'ignore' => true, 'decorators' => array('viewhelper') )); } } class siteanalysis_validate_passwordverification extends zend_validate_abstract { const not_match = 'notmatch'; protected $_messagetemplates = array( self::not_match => 'verifique que las contraseñs sean iguales.' ); public function isvalid($value, $context = null) { $value = (string) $value; $this->_setvalue($value); if (is_array($context)) { if (isset($context['passwdnew']) && ($value == $context['passwdnew'])) { return true; } } elseif (is_string($context) && ($value == $context)) { return true; } $this->_error(self::not_match); return false; } }
the problem not calling passwordverification custom validator, 1 see wrong it?
thanks.
update: test setup
$form = new siteanalysis_form_user_changepassword(); $value = 'adam'; $data = array('passwdverify' => $value); $validation = $form->isvalid($data); if ( $validation === false ) { $element = $form->getelement('passwdverify'); $errors = $element->geterrors(); $msg = $element->getmessages(); } else { $values = $form->getvalidvalues($data); }
if $value
- empty $errors "isempty"
- 'adam' $errors "nomatch" , "stringlengthtooshort"
- 'adamsandler' $errors "nomatch"
Comments
Post a Comment