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');