gpt4 book ai didi

php - codeigniter 中的表单验证总是返回 false

转载 作者:可可西里 更新时间:2023-11-01 00:56:19 25 4
gpt4 key购买 nike

我是 codeigniter 的新手,我不明白为什么我的 form_validation 一直返回 false。这是我的代码:

登录 Controller

class Login extends CI_Controller {

function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library('form_validation');
$this->load->library('session');
$this->load->model('user','',TRUE);
}

function index()
{
$this->load->view('login_view');
}

function user_registration_show(){

$this->load->view('registration_view');

}

function user_login_process(){


}

function user_registration_process(){

$this->form_validation->set_rules('fname', 'First Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('lname', 'Last Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('gender', 'Gender', 'trim|required|xss_clean');
$this->form_validation->set_rules('address', 'Address', 'trim|required|xss_clean');
$this->form_validation->set_rules('emailadd', 'Email Address', 'trim|required|xss_clean');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
$this->form_validation->set_rules('password1', 'Re-type Password', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE) {
$this->load->view('registration_view');
} else {

$pass = $this->input->post('password');
$pass1 = $this->input->post('password1');
if($pass!=$pass1){

$data['message_display'] = 'Password mismatched!';
}else{
$data = array(
'Fname' => $this->input->post('Fname'),
'Lname' => $this->input->post('Lname'),
'Gender' => $this->input->post('Gender'),
'Address' => $this->input->post('Address'),
'EmailAdd' => $this->input->post('EmailAdd'),
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
}

}
}
}

注册_查看

<?php echo form_open('login/user_registration_process'); ?>
<div class="content-box-wrapper">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" name="fname" placeholder="First Name" >
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" name="lname" placeholder="Last Name" >
</div>
</div>
<div class="form-group">
<div class="input-group">
<select class="form-control" name="gender" >
<option disabled="disabled">Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" name="address" placeholder="Address">
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="email" class="form-control" name="emailadd" placeholder="Email Address" >
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" name="username" placeholder="Username" >
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="password" class="form-control" name="password" placeholder="Password" >
</div>
</div>
<div class="form-group">
<div class="input-group">
<input type="password" class="form-control" name="password1" placeholder="Re-type Password" >
</div>
</div>
<input type="submit" class="btn btn-blue-alt btn-block" value="Register"/>
</div>
<?php echo form_close(); ?>

我正在使用 codeigniter 3.1.3。谁能帮帮我?

最佳答案

由于在所有字段中使用了 xss 干净检查,您的表单验证失败。如果您删除它,它会验证您的字段。因为您的数据已经被 xss 清理(假设 global_xss_filtering 在配置中为 TRUE)

关于php - codeigniter 中的表单验证总是返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41931822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com