setMessage() on email validator is not taken into account #2538

Closed
zfbot opened this Issue Sep 28, 2012 · 4 comments

Projects

None yet

4 participants

@zfbot
zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-493
Issue Type:Bug
Reporter:juriansluiman
Created:08/22/12
Assignee:weierophinney
Components:Zend\Validator

Description

In an InputFilter instance the "message" option (which will call the Zend\Validator\EmailAddress::setMessage() ) does not get through when an error is made.

The root cause is because the Zend\Validator\AbstractValidator::setMessage() uses $this->abstractOptions['messageTemplates'] and the template keys are not the keys from the EmailAddress validator. Therefore when every template has set its own message, the real messages for the EmailAddress validator aren't set.

Possible test case:


$this->add(array(
    'name'       => 'email',
    'required'   => true,
    'validators' => array(
        array(
            'name'    => 'EmailAddress',
            'options' => array(
                'message' => 'This is not a valid email address'
            )
        )
    ),
));

For an InputFilter attached to a Form which has an element called "email". If tested with "a@@com" as input, seven errors occur of which none uses the set message.

@zfbot
zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-493

Known GitHub users mentioned in the original message or comment:
@juriansluiman, @weierophinney

@Maks3w Maks3w closed this in 621c476 Jan 21, 2013
@weierophinney weierophinney added a commit that referenced this issue Jan 21, 2013
@weierophinney weierophinney Merge branch 'hotfix/3480'
Close #3480
Fixes #2538
10611f7
@Saeven
Saeven commented Mar 14, 2014

Am running into this on ZF 2.2.6 still. Trigger is simple, just submit a value that isn't an email address. The regex check supersedes the 'message' set, and returns two error messages instead of one. Understand that 'message' is supposed to be that one-message-to-rule-them-all?

@Saeven
Saeven commented Mar 19, 2014

I've found the issue, it's because Zend\Form\Element\Email adds its own default validator which is added atop whatever we configure as InputFilterSpecification. It doesn't respect the message key, and poorly, even duplicates checks if we try to configure a custom EmailAddress validator in the InputFilterSpecification itself. It'd ideally consider whether we have a customized EmailAddress validator in the InputFilterSpecification, and omit adding the default if a customized version exists.

@moleCuleFFF

I've run into this issue aswell surely this should be re-opened as it is clearly a bug and clearly not fixed ?

@philer philer referenced this issue in serlo-org/athene2-legacy Sep 2, 2014
Closed

unverständliche Fehlermelduhgen bei Registrierung #669

@gianarb gianarb pushed a commit to zendframework/zend-validator that referenced this issue May 15, 2015
@Maks3w Maks3w [Validator][zendframework/zendframework#2538] hostname validator over… 7cad0de
@weierophinney weierophinney added a commit to zendframework/zend-validator that referenced this issue May 15, 2015
@weierophinney weierophinney Merge branch 'hotfix/3480' ab588a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment