Different validation messages in different web bro

2019-09-06 02:22发布

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.....'
        ),

2条回答
SAY GOODBYE
2楼-- · 2019-09-06 02:48

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

查看更多
爷的心禁止访问
3楼-- · 2019-09-06 02:52

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

查看更多
登录 后发表回答