我是codeigniter的新手我一直在尝试为注册页面进行表单验证,但无论我输入什么,我的验证都会失败,请帮我解决这个问题 以下是我的观点:
<div class="signup-form"><!--sign up form-->
<h2>New User Signup!</h2>
<?php echo form_open('login/register');?>
<input type="text" name="name" placeholder="Name"/>
<input type="email" name="email" placeholder="Email Address"/>
<input type="password" name="password" placeholder="Password"/>
<button type="submit" class="btn btn-default">Signup</button>
</form>
</div><!--/sign up form-->
这是我的Conroller:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Login extends CI_Controller{
public function register(){
$this->load->library('form_validation');
$this->form_validation->set_rules('email','required|valid_email');
$this->form_validation->set_rules('password','required');
if($this->form_validation->run() === FALSE){
$this->load->view('test.php');
}
else{
$this->load->view('index.php');
}
}
}
答案 0 :(得分:-1)
主要原因此问题归因于事实this
@Tpojka的解决方案
代码中的小变化
public function register(){
$this->load->library('form_validation');
$this->form_validation->set_rules('email','required|valid_email');
$this->form_validation->set_rules('password','required');
if($this->form_validation->run() == FALSE){ //see here change
$this->load->view('test.php');
}
else{
$this->load->view('index.php');
}
}
==比较变量的值是否相等,必要时进行类型转换。 ===检查两个变量是否属于同一类型且具有相同的值。
$this->form_validation->run()
运行验证例程。成功时返回布尔值TRUE,失败时返回FALSE。
参考
http://au.php.net/manual/en/language.operators.comparison.php
Read this for Details //重要的读这个