2011-10-18 48 views
0

,我想添加自定義表單驗證我的price笨自定義表單驗證回調你好我使用笨表單驗證網址無法正常運作

我試圖在控制這個

$this->ci->form_validation->set_rules ('price', 'Price', 'callback_test'); 

和我有功能

private function test() 
{ 
    echo "hello"; die ; 
} 

我是試圖在此處添加自定義回撥網址test。但不工作

我將嘗試這個例子

http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks

,但我不喜歡這樣的工作驗證

$this->ci->form_validation->set_rules ('price', 'Price', 'required'); 

爲什麼我的回調URL功能不工作。請幫幫我 。謝謝..............

回答

3

您自定義的回調函數需要返回TRUE或FALSE才能正常工作。此外,把一個die()聲明中並沒有真正幫助你在這裏...

這是一個簡單的代碼示例,但我希望你得到的圖片:

$this->form_validation->set_rules ('price', 'Price', 'required|callback_test'); 

function test($string) 
{ 
    return ($string == 'something') ? TRUE : FALSE; 
} 

$string是從輸入 - 未來價值>後,並自動傳遞給你的回調函數。 您還需要爲此回調指定一條錯誤消息,否則您會收到「沒有爲自定義字段提供錯誤消息」或類似的錯誤。

$this->form_validation->set_message('test', 'The value you provided is not in the right format');