0
votes

I have read the CakePHP documentation about validation rules, but I'm still stuck with changing the error message on an email field.

I currently have this Validation rule in my model:

public $validate = array(
    'emailadres' => array(
        'rule'       => 'email',
        'required'   => true,
        'allowEmpty' => false,
        'message'    => 'My custom error message'
    )
);

The field shows up as being mandatory, but a standard error message appears instead of my custom message.

Does anybody see what I'm doing wrong?

My CakePHP version is 2.3.7

1

1 Answers

1
votes

You might want to double check the documentation: http://book.cakephp.org/2.0/en/models/data-validation.html#one-rule-per-field

Its not 'ruleName' => 'email',, but 'rule' => 'email',.

You can also try the verbose representation:

public $validate = array(
    'emailadres' => array(
        'email' => array(
            'rule'       => 'email',
            'required'   => true,
            'allowEmpty' => false,
            'message'    => 'My custom error message'
        )
    )
);