0

I am a newbie in CakePHP and doing my first application - first blog from cakephp tutorial. Everything is fine, but one thing bothers me. When I define validation rules in my model, validations are working.

But every web browser show different message. For example firefox show message in czech language (i'm from czech), chrome show "Please fill out this field" and internet explorer show "This field cannot be left blank".So i tried to translate the messages (by add parameter message into model validation). this is working, but only in internet explorer, other browsers are without change. Is there any way, how to have same validation messages same in all browsers?

Validation in model:

public $validate = array(
        'title' => array(
            'rule' => 'notEmpty',
            'message' => 'Please fill.....'
        ),
telman
  • 1
  • That field is automatically translated via PO files. See the documenation. – mark Jan 13 '14 at 14:43
  • That seems to be a problem with the `required` attribute for inputs (try this example http://www.wufoo.com/html5/attributes/09-required.html, it gives different errors in different browsers). As I understand, that's independent of cakephp or language implementation. You can try to change it like this http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message – Nunser Jan 13 '14 at 14:46
  • To Nunser: Thank you, i will try it.... – telman Jan 13 '14 at 16:48

2 Answers2

0

I think you are talking about client side validation messages. If I'm right the messages you see are created by your browser and are browser dipendant. Cake just tells the browser that the field is required by setting the required property in the input tag.

Instead the actual validation that cake does is made server side. If your browser sends data to the server then cake validates the data and returns error messages

arilia
  • 9,373
  • 2
  • 20
  • 44
0

There are two checks in place. The first one (that one that you see) ist the check on client side. The input field has a required parameter. So the browser knows that the field can't be blank and says than in it's language. Nothing is sent to the server till now. After filling in and sending the form, then the second check is in place which is the cakephp validation.

Try it with this:

    'title' => array(
        'kosher' => array(
            'rule' => 'email',
            'message' => 'Please make sure your email is entered correctly.'
        ),
        'required' => array(
            'rule' => 'notEmpty',
            'message' => 'Please enter your email.'
        )

Then you will see: 1) if you enter nothing, then the browser message appears (client side), 2) if you enter some text, which is no email, then the message from above appears ('Please enter your email.')

FishWave
  • 308
  • 2
  • 16