2010-04-14 154 views
1

請請請誰能幫我笨表單驗證問題

$this->load->library('form_validation'); 
    $this->load->helper('cookie'); 

    $data = array(); 


    if($_POST) { 
    // Set validation rules including additional validation for uniqueness 
    $this->form_validation->set_rules('yourname', 'Your Name', 'trim|required'); 
    $this->form_validation->set_rules('youremail', 'Your Email', 'trim|required|valid_email'); 
    $this->form_validation->set_rules('friendname', 'Friends Name', 'trim|required'); 
    $this->form_validation->set_rules('friendemail', 'Friends Email', 'trim|required|valid_email'); 

    // Run the validation and take action 
    if($this->form_validation->run()) { 
    echo 'valid; 
    } 
    } 
    else{ 
    echo 'problem'; 
    } 

表單驗證是回來了,沒有錯誤可以攜載一個知道爲什麼嗎?

回答

1

它實際上回顯'有效'嗎? (你缺少撇號出現,順便說一句)

告訴你當$ _ POST是假的,只會附和「問題」的代碼,而不是當驗證失敗。 不知道更多,它可能是簡單的:

// Run the validation and take action 
if($this->form_validation->run()) { 
echo('valid'); 
} else { 
echo('invalid'); 
} 
0

嘗試這樣沒有如果$ _ POST設置檢查 - 不是真的需要:

//validation rules here 
// 
if ($this->form_validation->run() == TRUE) { 
    //do whatever that shall be run on succeed 
} else { 
    $this->load->view('form'); //load the form 
} 

瞭解更多關於控制器部分here