Php Codeigniter验证不工作,页面正在重定向到空白页面

Php Codeigniter验证不工作,页面正在重定向到空白页面,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,我是codeigniter的新手。这两个页面的位置都正确。我想有一些代码可以激活查看页面的表单验证程序 编辑:我添加了 if ($this->form_validation->run()){ $this->load->view('home'); }else{ $this->load->view('login'); } 控制器中的上述代码仍然将页面重定向到空白页面 <?php class We

我是codeigniter的新手。这两个页面的位置都正确。我想有一些代码可以激活查看页面的表单验证程序

编辑:我添加了

          if ($this->form_validation->run()){
$this->load->view('home');
    }else{
  $this->load->view('login');
      }  
控制器中的上述代码仍然将页面重定向到空白页面

   <?php  

 class Welcome extends CI_Controller {
  function __construct()
    {
        parent:: __construct();
        $this->load->helper(array('form', 'url', 'html'));
        $this->load->library('form_validation');               
         $this->load->database();

    }
public function index()
{       
    $this->form_validation->set_rules('username','username', 'required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('email','email', 'trim|required|valid_email');


         $this->form_validation->run();
    $this->load->view('login');
 {



   }
   }
   ?>

这里是查看页面。我还使用了纯html表单标记而不是form_open方法,但它也不起作用,它将我重定向到同一页面,并且没有显示任何错误

            <!DOCTYPE html>
             <html lang="en">
             <head>
                    <meta charset="utf-8">
                      <title>Welcome to CodeIgniter</title>
                       </head>
                        <body>
                        <div id="container">
<?php echo validation_errors('form'); ?>
<?php echo form_open('form'); ?>

 <?php echo form_error('username');  ?>
 <input type='text' name ='username' >
 <?php echo form_error('email');  ?>
 <input type='email' name='email'>

 <input type="submit" value='go'>
  </form>
  </div>

      </body>
     </html>

欢迎来到CodeIgniter
试试这个

在视图中

使用这个

if ($this->form_validation->run()){
    $this->load->view('home');
}else{
      $this->load->view('login');
}

更改索引函数的完整主体,如下所示

if (isset($_POST)) {
    $this->form_validation->set_rules('username','username','required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('email','email','trim|required|valid_email');

    if($this->form_validation->run()){
        $this->load->view('home');
    }else{
        $this->load->view('login');
    }
} else {
    $this->load->view('login');
}

我试过了。仍然不起作用:(你可以试试这个它不起作用
你的控制器名是表单吗?提交后,它将我重定向到“about:blank”查看控制器的最后一行“$this->load->view('login')@SumitBhatia否。这是在提交页面之后。我是指第一次如何加载。发布控制器代码。如果您解释了为什么它会工作,您的答案将更有帮助。
if ($this->form_validation->run()){
    $this->load->view('home');
}else{
      $this->load->view('login');
}
if (isset($_POST)) {
    $this->form_validation->set_rules('username','username','required|min_length[5]|max_length[15]');
    $this->form_validation->set_rules('email','email','trim|required|valid_email');

    if($this->form_validation->run()){
        $this->load->view('home');
    }else{
        $this->load->view('login');
    }
} else {
    $this->load->view('login');
}