Codeigniter表单验证运行始终返回FALSE

时间:2017-01-22 21:37:48

标签: php codeigniter

我修改了一些用户注册教程中的一些代码,但我不知道它为什么不起作用。在修改之前,它有效。我只是在数据库和表单中添加了几个记录到表中。

这是控制器中的一项功能,其中' $ this-> form_validation-> run()== FALSE'总是返回FALSE 如果我删除form_validation和if / else语句,它会将记录添加到数据库,但如果存在form_validation,它总是转到$ this-> index

控制器用户的片段

public function registration()
{
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'UserName','required|min_length[5]');
    $this->form_validation->set_rules('email', 'Email','required|min_length[5]');
    $this->form_validation->set_rules('password', 'Password','required|min_length[5]');
    $this->form_validation->set_rules('con_password', 'Password Confirmation', 'required|matches[password]');
    $this->form_validation->set_rules('firstname', 'firstname','required|min_length[5]'); 
    $this->form_validation->set_rules('lastname', 'lastname','required|min_length[5]');
    $this->form_validation->set_rules('adress', 'adress','required|min_length[5]');


    if($this->form_validation->run() == FALSE)
    {
    $this->index();


    }
    else
    {
        $this->user_model->add_user();
        redirect("users/index");
    }

}

这是我的查看文件

<div class="registration">



<h1>Registration</h1>
 <?php echo validation_errors('<p class="error">'); ?>
 <?php echo form_open("users/registration"); ?>
  <p>
  <label for="username">Username:</label>
  <input type="text" id="username" name="username" value="" />
  </p>
  <p>
  <label for="email">Email:</label>
  <input type="text" id="email" name="email" value="" />
  </p>
  <p>
  <label for="password">Password:</label>
  <input type="password" id="password" name="password" value="" />
  </p>
  <p>
  <label for="con_password">Confirm Password</label>
  <input type="password" id="con_password" name="con_password" value="" />
  </p>
  <p>
  <label for="firstname">Name</label>
  <input type="text" id="firstname" name="firstname" value="" />
  </p>
  <p>
  <label for="lastname">Lastname</label>
  <input type="text" id="lastname" name="lastname" value="" />
  </p>
  <p>
  <label for="adress">Address</label>
  <input type="text" id="adress" name="adress" value="" />
  </p>
  <p>
  <input type="submit"  value="Submit" />
  </p>

 <?php echo form_close(); ?>

</div><!--registration-->

模型的片段

public function add_user()
{
      $data=array(
        'username'=>$this->input->post('username'),
        'email'=>$this->input->post('email'),
        'password'=>md5($this->input->post('password')),
        'permissions'=>'Normal',
        'firstname'  =>$this->input->post('firstname'),
        'lastname'  =>$this->input->post('lastname'),
        'adress'  =>$this->input->post('adress')
      );
    $this->db->insert('users',$data);
}

这有什么问题?

0 个答案:

没有答案