I want to create a form in Zend framework. I am using the code below for a f开发者_高级运维ield:
$this->addElement('text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'alnum'
)
));
This works. But now I also want to add a new validator. In this case StrinLength
$element->addValidator('StringLength', false, array(6, 20));
How can I add this validator in the array I already have? Tnx in advanced
Doesn't this work:
<?PHP
$this->addElement('text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'alnum',
array('StringLength', false, array(6,20))
)
));
Similar to the example given in the manual
You can specify the names of arguments to the addValidator() method as array keys:
$this->addElement('text', 'username', array(
'label' => 'Username:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'alnum',
// See below
array(
'validator' => 'StringLength',
'options' => array(6, 20)
)
)
));
精彩评论