我正在尝试验证表单,但验证始终返回false,validation_errors()
返回空字符串。我无法理解这段代码有什么问题:
function submission_register_form(){
if (!$this->input->is_ajax_request()) { exit('no valid req.'); }
$FormRules = array(
array(
'field' => 'email',
'label' => 'Email Address',
'rules' => 'required|valid_email|xss_clean|callback_email_check'
),
array(
'field' => 'password1',
'label' => 'Password',
'rules' => 'required|min_length[4]|xss_clean'
),
);
$this->form_validation->set_rules($FormRules);
if ($this->form_validation->run() == TRUE){
$email = $this->input->post('email');
$username = $email;
$password = $this->input->post('password1');
if ($this->ion_auth->register($username, $password, $email, $meta,NULL) == TRUE) {
echo '<div class="success">Thank you for registering. To activate your account, please click on the link in the activation message which has been sent to your e-mail address.</div>';
} else {
echo '<div class="success">Registration did not complete. Please contact the site administrator.</div>';
}
}
else {
echo '<div class="errors">'.validation_errors().'</div>';
}
}
这是我的html表单:
<div class="login-form">
<a href="/auth/login" class="signup">Log In <img src="<?php echo base_url('images/right-arrow-red.png')?>" alt="" /></a>
<h2>Create an Account</h2>
<p>Howday! Welcome!</p>
<div class="jsError"></div>
<?php echo form_open('auth/submission_register_form', array('class'=>'signupjsform')); ?>
<div class="input">
<label for="email">EMAIL ADDRESS</label>
<input type="text" id="email" name="email" placeholder="example@site.com" />
</div>
<div class="input">
<label for="password">PASSWORD</label>
<input type="password" id="password" name="password1" placeholder="your password" />
</div>
<div class="check_forgot fix">
<p>By Signing up, you agree with our <a href="#">Terms of Service</a> and <a href="#">Privacy Statement</a>.</p>
</div>
<div class="submit">
<p><input type="submit" value="SIGN IN" /> <span>OR</span> <a href="#"><img src="<?php echo base_url('images/facebook-icon.png')?>" alt="" /> SIGN UP WITH FACEBOOK</a></p>
</div>
<?php echo form_close(); ?>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('form.signupjsform').on('submit', function(form){
form.preventDefault();
$.post('/index.php/auth/submission_register_form', $('form.jsform').serialize(), function(data){
alert(data);
$('div.jsError').html(data);
});
});
});