问题描述
我是CakePHP的新手,做我的第一个应用程序 - 从cakephp教程的第一个博客。一切都很好,但有一件事困扰我。当我在我的模型中定义验证规则时,验证正在工作。
但是每个网络浏览器都显示不同的消息。例如firefox显示消息在czech语言(我来自捷克),chrome显示请填写此字段和互联网浏览器显示此字段不能留空。我试图翻译消息(通过添加参数消息进入模型验证)。这是工作,但只有在互联网浏览器,其他浏览器是没有改变。
在模型中验证:
public $ validate = array(
'title'=> array(
'rule'=>'notEmpty',
'message'=> ;'请填写.....'
),
有两个检查,第一个(你看到的)是客户端检查。输入字段有一个必需的参数,因此浏览器知道该字段不能为空,没有什么可以发送到服务器直到现在,填写并发送表单后,第二个检查就是cakephp验证。
尝试使用:
'title'=> array(
/ pre>
'kosher'=> array
'rule'=>'email',
'message'=>'请确保您的电子邮件输入正确。
),
'required'=> ;数组(
'rule'=>'notEmpty',
'message'=>'请输入您的电子邮件'。
)
然后你会看到:1)如果你不输入任何内容,则显示浏览器消息(客户端),2)如果输入一些文本,电子邮件,则会显示上方的讯息(请输入您的电子邮件。)
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.....' ),
解决方案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.')
这篇关于在不同的Web浏览器中的不同的验证消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!