Codeigniter,不回显validation_error();

时间:2015-01-01 19:41:30

标签: php forms codeigniter

我创建了一个新控制器questions.php,它不是默认控制器。我已经加载了form_validation库,但是当我从表单中提交空字段时,它没有回显验证错误。 SO中的其他问题似乎与我的情况完全无关。

以下是我的questions.php控制器。顺便说一下,我只发布了类控制器的必要位。

<?php
class Questions extends CI_Controller{
    function __construct() {
        parent::__construct();
        $this->load->helper(array('form'));
        $this->load->library("form_validation");
    }

    public function user_logged_in(){
     $this->load->library('../controllers/main');

     $obj = new $this->main();
     $status = $obj->logged_in();
          if($status){
          return true;
        }else{
         return false;
      }
   }
    public function question_validation(){
        if($this->user_logged_in() == false){
            redirect('main/index');
        } else{
            $this->load->library('form_validation');
            $this->form_validation->set_rules('input_title','Title','required');
            $this->form_validation->set_rules('message','Question Details','required');
            $this->form_validation->set_rules('vidya','Tags','required');

            if($this->form_validation->run() == false){
                $this->load->library('../controllers/main');
                $obj = new $this->main();
                $getUserData = $obj->getLogged_userData();
                $userdata = array(
                    'uservalues' => $getUserData
                );

                $this->load->view('view_header'); 
                $this->load->view('view_nav',$userdata);
                $this->load->view('log_user/user_second_nav');  
                $this->load->view('question_posts/post_questions');
                $this->load->view('view_footer');
            } else{
                echo "form has been submitted";
       }
    }

}
?>

视图中的表单页面post_questions.php,如下所示,

<?php
    $this->load->helper("form");
    echo validation_errors();
    echo form_open('questions/question_validation');
?>
<p><h2>Question title</h2></p>
<p><input type="text" name="input_title" id="input_title"   
placeholder="what is your question please be specific and clear"></p>

<p><h3>Now Describe in detail!</h3>
<p><textarea id="message" name="message" rows="10px" cols="86px"></textarea></p>
<p><h3>Tags</h3></p><p><input type="text" id="vidyagames" name="vidya"></p>
<p><input type="submit" name="post" value="Submit"></p>
</form>

在此之前,问题控制器给我一个错误,如未定义的属性Questions::$form_validation所以我添加了一个__construct(),现在它不会回应表单验证错误。

你可以帮助我吗,因为表格可能根本没有提交。 提前谢谢。

0 个答案:

没有答案