2012-06-30 124 views
2

在我的控制器中我設置的規則是這樣codeignitor表單驗證錯誤

$this->form_validation->set_rules("contact_name[]","Contact Name","required|max_length[25]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_title[]","Contact Title","required|max_length[25]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_main[]","Contact Main Number","required|max_length[45]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_direct[]","Contact Direct Number","required|max_length[45]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_cell[]","Contact Cell Number","required|max_length[45]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_primary","Primary","required|max_length[45]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_fax[]","Fax","required|max_length[105]|xss_clean|htmlspecialchars"); 
     $this->form_validation->set_rules("contact_email[]","Contact Email ID","required|max_length[105]|xss_clean|htmlspecialchars"); 

和張貼我會得到這樣的事情

array 
    'company' => string 'Sccc' (length=4) 
    'name' => string 'Ajay ccc' (length=8) 
    'address' => string 'ccsd' (length=4) 
    'city' => string 'City name' (length=9) 
    'state' => string '20' (length=2) 
    'zip' => string '665996555' (length=9) 
    'country' => string '6' (length=1) 
    'category' => string 'popular' (length=7) 
    'credit' => string '2566' (length=4) 
    'website' => string 'ccc' (length=3) 
    'primary_flag' => string '1' (length=1) 
    'discount' => string '0' (length=1) 
    'payment_terms' => string '6' (length=1) 
    'customerid' => string 'ccc' (length=3) 
    'notes' => string 'cc' (length=2) 
    'contact_name' => 
    array 
     0 => string 'Dileep' (length=6) 
     1 => string 'Dileep' (length=6) 
     2 => string 'Dileep' (length=6) 
     3 => string 'Dileep' (length=6) 
     4 => string 'Dileep' (length=6) 
     5 => string 'Dileep' (length=6) 
     6 => string 'Dileep' (length=6) 
     7 => string 'Dileep' (length=6) 
     8 => string 'Dileep' (length=6) 
    'contact_primary' => 
    array 
     0 => string 'true' (length=4) 
     1 => string 'false' (length=5) 
     2 => string 'false' (length=5) 
     3 => string 'false' (length=5) 
     4 => string 'false' (length=5) 
     5 => string 'false' (length=5) 
     6 => string 'false' (length=5) 
     7 => string 'false' (length=5) 
     8 => string 'false' (length=5) 
    'contact_title' => 
    array 
     0 => string 'Curio' (length=5) 
     1 => string 'Curio' (length=5) 
     2 => string 'Curio' (length=5) 
     3 => string 'Curio' (length=5) 
     4 => string 'Curio' (length=5) 
     5 => string 'Curio' (length=5) 
     6 => string 'Curio' (length=5) 
     7 => string 'Curio' (length=5) 
     8 => string 'Curio' (length=5) 
    'contact_main' => 
    array 
     0 => string '66558-66554-6665' (length=16) 
     1 => string '66558-66554-6665' (length=16) 
     2 => string '66558-66554-6665' (length=16) 
     3 => string '66558-66554-6665' (length=16) 
     4 => string '66558-66554-6665' (length=16) 
     5 => string '66558-66554-6665' (length=16) 
     6 => string '66558-66554-6665' (length=16) 
     7 => string '66558-66554-6665' (length=16) 
     8 => string '66558-66554-6665' (length=16) 
    'contact_direct' => 
    array 
     0 => string '5555-666-555' (length=12) 
     1 => string '5555-666-555' (length=12) 
     2 => string '5555-666-555' (length=12) 
     3 => string '5555-666-555' (length=12) 
     4 => string '5555-666-555' (length=12) 
     5 => string '5555-666-555' (length=12) 
     6 => string '5555-666-555' (length=12) 
     7 => string '5555-666-555' (length=12) 
     8 => string '5555-666-555' (length=12) 
    'contact_cell' => 
    array 
     0 => string '555-6654-555' (length=12) 
     1 => string '555-6654-555' (length=12) 
     2 => string '555-6654-555' (length=12) 
     3 => string '555-6654-555' (length=12) 
     4 => string '555-6654-555' (length=12) 
     5 => string '555-6654-555' (length=12) 
     6 => string '555-6654-555' (length=12) 
     7 => string '555-6654-555' (length=12) 
     8 => string '555-6654-555' (length=12) 
    'contact_fax' => 
    array 
     0 => string '996-5565-656' (length=12) 
     1 => string '996-5565-656' (length=12) 
     2 => string '996-5565-656' (length=12) 
     3 => string '996-5565-656' (length=12) 
     4 => string '996-5565-656' (length=12) 
     5 => string '996-5565-656' (length=12) 
     6 => string '996-5565-656' (length=12) 
     7 => string '996-5565-656' (length=12) 
     8 => string '996-5565-656' (length=12) 
    'contact_email' => 
    array 
     0 => string '[email protected]' (length=20) 
     1 => string '[email protected]' (length=20) 
     2 => string '[email protected]' (length=20) 
     3 => string '[email protected]' (length=20) 
     4 => string '[email protected]' (length=20) 
     5 => string '[email protected]' (length=20) 
     6 => string '[email protected]' (length=20) 
     7 => string '[email protected]' (length=20) 
     8 => string '[email protected]' (length=20) 
    'userfile2' => string '' (length=0) 
    'contact_log' => 
    array 
     0 => string 'Waiting for the release....' (length=27) 
    'contact_time' => 
    array 
     0 => string '6/30/12' (length=7) 
    'contact_duedate' => 
    array 
     0 => string '12/01/2012' (length=10) 
後的HTML是=>

<input type="text" name="contact_name[]" value="Dileep" class="t_contact_name"> 
    //and some others too as name as array 

但是,當我運行窗體驗證我得到一些錯誤

A PHP Error was encountered 

Severity: Warning 

Message: mb_strlen() expects parameter 1 to be string, array given 

Filename: libraries/Form_validation.php 

Line Number: 1003 
A PHP Error was encountered 

Severity: Warning 

Message: htmlspecialchars() expects parameter 1 to be string, array given 

Filename: libraries/Form_validation.php 

Line Number: 619 

什麼是真正的問題或我做錯了什麼?

請幫幫我。

在此先感謝。

編輯

請檢查輸入的名稱是陣列,還有比同類型項目values.So我需要使用字段名作爲數組。

根據codeignitor表單驗證我可以使用containsng字段名稱作爲數組驗證表單。

+0

這是寫在錯誤消息 –

+0

@DamienPirsy我知道錯誤,我想關閉錯誤。 – Red

回答

2

您的輸入是由數組組成的,而函數max_lengthhtmlspecialchars只需要一個字符串。

當只有一個值使用這種類型的輸入:

<input type="text" name="contact_name" value="Dileep" class="t_contact_name"> 

在輸入其中陣列是一個必須不使用上述功能。

+0

Nop,還有更多值..請檢查數組。 – Red

+0

在這種情況下,您不能使用這些功能。創建您自己的驗證功能。 –

+0

CI表示「表單驗證類支持使用數組作爲字段名稱」 – Red