Hi. I try to validate my form. But get errors.
// Captcha
$captchaId = new Hidden('captcha[id]');
$captchaId->setAttributes(array(
'name' => 'captcha[id]',
'value' => $captchaIdCode,
'required' => true,
'autocomplete' => 'off',
));
$captchaId->setFilters(array('striptags', 'trim', 'string'));
$captchaId->addValidators(array(
new PresenceOf(array(
'message' => 'Name is required'
)),
new StringLength(array(
'min' => 32,
'max' => 32,
'messageMinimum' => 'Minimum',
'messageMaximum' => 'Maximum',
))
));
$this->add($captchaId);
// Captcha
$captchaInput = new Text('captcha[input]');
$captchaInput->setAttributes(array(
'placeholder' => $this->translator->trans('Captcha'),
'id' => 'captcha',
'name' => 'captcha[input]',
'required' => true,
'autocomplete' => 'off',
));
$captchaInput->setFilters(array('striptags', 'trim', 'string'));
$captchaInput->addValidators(array(
new PresenceOf(array(
'message' => 'Name is required'
)),
new StringLength(array(
'min' => 8,
'max' => 8,
'messageMinimum' => 'Minimum',
'messageMaximum' => 'Maximum',
))
));
$this->add($captchaInput);
This is my post data
Array
(
[captcha] => Array
(
[id] => 7e0ab94c212006dec468e01f86e0babb
[input] => fd1dfDGS
)
[csrf] => TwEJe8k5UQmjB2Ut
)
Get these messages
Phalcon\Validation\Message\Group Object
(
[_position:protected] => 0
[_messages:protected] => Array
(
[0] => Phalcon\Validation\Message Object
(
[_type:protected] => PresenceOf
[_message:protected] => Name is required
[_field:protected] => captcha[id]
[_code:protected] => 0
)
[1] => Phalcon\Validation\Message Object
(
[_type:protected] => TooShort
[_message:protected] => Minimum
[_field:protected] => captcha[id]
[_code:protected] => 0
)
[2] => Phalcon\Validation\Message Object
(
[_type:protected] => PresenceOf
[_message:protected] => Name is required
[_field:protected] => captcha[input]
[_code:protected] => 0
)
[3] => Phalcon\Validation\Message Object
(
[_type:protected] => TooShort
[_message:protected] => Minimum
[_field:protected] => captcha[input]
[_code:protected] => 0
)
)
)