PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to change CakePHP validation error message

 April 22, 2022     cakephp, cakephp-2.3     No comments   

Issue

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


Solution

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'
        )
    )
);


Answered By - mark
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,259,941

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing