我正在使用cakephp 2.5.2创建一个项目。我用"电子邮件"的字段做了一个简单的签名表格。和#34;密码"。文件名是Login文件夹中的admin_index.php。
<?php
echo $this->Form->create('Login', array('novalidate'=> true));
?>
<div class="log-input">
<div class="log-input-left">
<?php echo $this->Form->input('email',array('class'=>'user required','label'=>false,'placeholder'=>'Enter Email')); ?>
</div>
<div class="clearfix"> </div>
</div>
<div class="log-input">
<div class="log-input-left">
<?php echo $this->Form->input('password',array('class'=>'lock required','label'=>false,'placeholder'=>'Enter Password')); ?>
</div>
<div class="clearfix"> </div>
</div>
<?php
$options = array(
'label' => 'Login'
);
echo $this->Form->end($options);
?>
</div>
<div class="new_people">
<h4>For New People</h4>
<p>Having hands on experience in creating innovative designs,I do offer design
solutions which harness.</p>
<a href="sign-up.html">Register Now!</a>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#LoginAdminIndexForm').validate({
});
});
</script>
我想同时应用客户端和服务器端的两种验证类型。对于客户端验证,我包括jquery.valdation.js文件和ctp文件中验证字段的调用脚本。对于服务器端验证,请在模型文件(Model / Login.php)上编写规则。
<?php
class Login extends AppModel {
public $useTable = 'admins';
var $validate = array(
'email' => array(
'email_must_not_be_blank' => array(
'rule' => 'notEmpty',
'message' => 'Email cant be blank.'
),
'email_must_be_valid_syntax' => array(
'rule' => 'email',
'message' => 'Email is not valid.'
),
'email_must_be_unique' => array(
'rule' => 'isUnique',
'message' => 'Email is already exist.'
),
),
'password' => array(
'length' => array(
'rule' => array('between', 5, 40),
'message' => 'Your password must be between 8 and 40 characters.',
),
)
);
}
控制器文件是:
class LoginsController extends AppController {
public $uses = array('Login');
public $name='Login';
public function admin_index() {
if($this->request->is('post')){
$this->Login->set($this->request->data);
if ($this->Login->validates()) {
} else {
$errors = $this->Login->validationErrors;
}
}
$this->layout = 'login';
$this->render('admin_index');
}
}
问题是,如果我没有应用模型验证但是使用双方验证,则客户端验证工作正常,jquery验证不起作用。意味着,首先jquery验证应该调用,但在这种情况下服务器端验证工作而不是jquery验证。 另外,我在布局文件夹中包含了jquery库和jquery.validation.js文件。 有人可以帮我解决这个问题。