2012-06-22 69 views
0

似乎有很多關於表單驗證的問題,但沒有人回答我的問題。Codeigniter表單驗證將不會運行

除非我遺漏明顯的東西,否則我的表單驗證將不會運行,但只在某個頁面上,所有其他頁面都可以。

這裏的問題是代碼:

public function activate($code = '') 
    { 
     // This function lets a user activate their account with the code or link they recieved in an email 
     if($code == '' || isset($_POST[''])){ 
      $form = ''; 
      $this->load->library('form_validation'); 
      $this->load->helper('form'); 

      if ($this->form_validation->run() == FALSE){ 
       // No code, so display a box for them to enter it manually 
       $this->form_validation->set_rules('activation_code', 'Activation Code', 'trim|required|xss_clean|integer'); 

       $form .= validation_errors(); 
       $form .= form_open_multipart('user/activate', array('class' => 'formee')); 

       $form .= form_label('Enter your activation code below and click \'Activate\' to start using your account. If you need a hand please contact live chat.', 'activation_code'); 
       $form .= form_input(array('name' => 'activation_code')); 

       $data = array(
        'name'  => 'submit', 
        'value'  => 'Activate', 
        'class'  => 'right', 
        'style'  => 'margin-top:10px;', 
       ); 

       $form .= form_submit($data); 
       $form .= form_close(); 
      }else{ 
       $form .= "form run"; 
      } 
     }else{ 
      // Code recieved through the GET or POST variable XSS clean it and activate the account 
     } 

     $data = array(
      'title' => $this->lang->line('activate_title'), 
      'links' => $this->gen_login->generate_links(), 
      'content' => $form 
     ); 
     $this->parser->parse('beer_template', $data); 
    } 

您可以在這裏看到的頁面:http://77.96.119.180/beer/user/activate

你可以看到表單驗證工作在這裏:http://77.96.119.180/beer/user/register

誰能幫助?

回答

3

您撥打set_rules運行後:

if ($this->form_validation->run() == FALSE){ 
    // No code, so display a box for them to enter it manually 
    $this->form_validation->set_rules('activation_code', 'Activation Code', 'trim|required|xss_clean|integer'); 

但應該是前:

$this->form_validation->set_rules('activation_code', 'Activation Code', 'trim|required|xss_clean|integer'); 
if ($this->form_validation->run() == FALSE){ 
}