On the page there are several fields with different names, by default - one at a time:

<input type="text" name="name[]"> 

The data is serialized and transmitted by AJAX. On the PHP side, I accept this

 parse_str($_POST['data'], $params); // POST PARENT $_POST['name[]'] = $params['name']; $_POST['lastname[]'] = $params['lastname']; 

Further validation of CI:

 $this->form_validation->set_rules('name[]', 'Parent name', 'required|xss_clean|htmlspecialchars|min_length[2]|max_length[10]|alpha'); 

During validation, I get an error:

 <p>Severity: Warning</p> <p>Message: preg_match() expects parameter 2 to be string, array given</p> <p>Filename: libraries/Form_validation.php</p> <p>Line Number: 1172</p> 

From the error it is clear that the array is flying to the processing, and not the string ... But earlier when the array is received, the name , and the name [] rule assignments - everything worked fine ...

Full validation code:

 // PARENT VALIDATION $this->form_validation->set_rules('name[]', 'Parent name', 'required|xss_clean|htmlspecialchars|min_length[2]|max_length[10]|alpha'); $this->form_validation->set_rules('lastname[]', 'Parent secondname', 'required|xss_clean|htmlspecialchars|min_length[2]|max_length[14]|alpha'); $this->form_validation->set_rules('status[]', 'Status', 'required|integer'); $this->form_validation->set_rules('area[]', 'Sector', 'required|integer'); $this->form_validation->set_rules('street[]', 'Street', 'required|xss_clean|htmlspecialchars|min_length[3]|max_length[20]'); $this->form_validation->set_rules('block[]', 'Block', 'required|numeric'); $this->form_validation->set_rules('mobile[]', 'Mobile', 'required|min_length[8]|man_length[9]|numeric'); $this->form_validation->set_rules('phone[]', 'Phone', 'required|min_length[8]|max_length[9]|numeric'); $this->form_validation->set_rules('email[]', 'Return email', 'xss_clean|valid_email'); $this->form_validation->set_rules('apart[]', 'Apartament', 'numeric'); // CHILDREN VALIDATION $this->form_validation->set_error_delimiters('<li>', '</li>'); $this->form_validation->set_rules('nameChild', 'Child name', 'required|trim|xss_clean|htmlspecialchars|min_length[2]|max_length[10]|alpha'); $this->form_validation->set_rules('lastnameChild', 'Child secondname', 'required|trim|xss_clean|htmlspecialchars|min_length[2]|max_length[14]|alpha'); $this->form_validation->set_rules('kindergartner', 'Gradinita', 'required|integer'); $this->form_validation->set_rules('streetChild', 'Child Street', 'required|trim|xss_clean|htmlspecialchars|min_length[3]|max_length[20]'); $this->form_validation->set_rules('area', 'Area', 'required|integer'); $this->form_validation->set_rules('sex', 'Sex', 'required|integer'); $this->form_validation->set_rules('limba', 'Limba', 'required|integer'); $this->form_validation->set_rules('idnp', 'IDNP', 'required|trim|min_length[13]|max_length[13]|numeric'); $this->form_validation->set_rules('captcha', 'Code', 'trim|required|exact_length[5]|alpha|callback__captcha_check'); 
  • Show your entire validation code - Victor Halauko
  • one
    ON line 1172 is checking for is integer. see where you use this check "| integer" - Victor Halauko
  • Added the full validation code in the question - Jony
  • Do you have an array in the array? And then he writes: "I want to accept the string, and you give an array" Look in the profiler that you are transmitting - Victor Halauko

1 answer 1

I also see strangeness:

  $this->form_validation->set_rules('area[]', 'Sector', 'required|integer'); 

and

  $this->form_validation->set_rules('area', 'Area', 'required|integer'); 

In the first case, you validate the area as an array. In the second case, you validate the string, and in the form you pass an array. most likely because of this and the problem ...

PS That says about the bug in the framework. But I'm not sure. look again carefully form and check.

  • I'll check it out, maybe - Jony
  • But if we receive a critical error due to the data sent from the client, then this is a specific bug in the framework - Victor Halauko
  • All the same ... 'area' replaced by name 'areaChild' - the same error - Jony
  • And comment out in general vadidatsiyu with area. Now what? - Victor Halauko
  • Found an error - the kindergartner field, it was without [], and the data contained as an array. Thanks to everyone - Jony