在我的控制器中,我正在设置这样的规则
$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");
html是=>
<input type="text" name="contact_name[]" value="Dileep" class="t_contact_name">
//and some others too as name as array
发布后我会得到这样的东西
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 'mailer@mail.com' (length=20)
1 => string 'mailer@mail.com' (length=20)
2 => string 'mailer@mail.com' (length=20)
3 => string 'mailer@mail.com' (length=20)
4 => string 'mailer@mail.com' (length=20)
5 => string 'mailer@mail.com' (length=20)
6 => string 'mailer@mail.com' (length=20)
7 => string 'mailer@mail.com' (length=20)
8 => string 'mailer@mail.com' (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)
但是当我运行表单验证时,我遇到了一些错误
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
真正的问题是什么或我做错了什么?
编辑
请检查输入名称是否为数组,有多个相同类型的值。所以我需要使用字段名称作为数组。
根据 codeigniter 表单验证,我可以使用包含字段名称作为数组来验证表单。