php - codeigniter表单验证错误

标签 php arrays codeigniter validation

在我的 Controller 中,我设置这样的规则

$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 '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb868a82878e99ab868a8287c5888486" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      1 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f9949890959c8bb994989095d79a9694" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      2 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c010d0500091e2c010d0500420f0301" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      3 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0ada1a9aca5b280ada1a9aceea3afad" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      4 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed808c8481889fad808c8481c38e8280" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      5 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="761b171f1a1304361b171f1a5815191b" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      6 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="167b777f7a7364567b777f7a3875797b" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      7 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="375a565e5b5245775a565e5b1954585a" rel="noreferrer noopener nofollow">[email protected]</a>' (length=20)
      8 => string '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="422f232b2e2730022f232b2e6c212d2f" rel="noreferrer noopener nofollow">[email protected]</a>' (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 表单验证,我可以使用包含字段名称作为数组来验证表单。

最佳答案

您的输入由数组组成,而函数 max_lengthhtmlspecialchars 需要单个字符串。

当只有一个值时,使用这种类型的输入:

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

在必须使用数组的输入上,请勿使用上述函数。

关于php - codeigniter表单验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11272775/

相关文章:

php - 如何从数据库反序列化 codeigniter session 数据

php - 带有 pdo_pgsql 安装问题的 Docker PHP

php - linux下编辑PHP ini文件问题

php - str_replace 仅使用整个单词

php - 使用 html 表单导入 csv 数据...使用 PHP 脚本加载数据 infile 和 MySQL

javascript - jQuery 自动完成,3 个值或更多

java - 如何标记文件并将数据输入到数组中?

javascript - 如何获取数组的每第三个元素

php - 如何根据多个值进行多列选择?

javascript - 在 CodeIgniter 中单击按钮时出现无效标志到正则表达式错误