2012-06-22 36 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){ 
}