I need to set form validation rules in codeigniter from an AJAX call The call generates a $_POST array where i nest data from different forms (1:N) and then I set validation rules in this way:
$this->form_validation->set_rules($field, $label , $rules);
and the $_POST array will be similar at this:
field1: value1
field2: value2
field3: value3
field4: value4
field5: value5
field6: value6
id: 86
operation: "add"
clearly, some forms may have colliding names, and this solution is not reliable.
For example
field1:value1
field1:value2
names are given dinamically, so i can't afford to change them.
I choose to nest values in $_POST array:
form:
form1:
field1: value1
field2: value2
form2:
field1: value3
field2: value4
form3:
field1: value5
field2: value6
id: 86
operation: "add"
but now form_validation is broken.
$this->form_validation->set_rules('form[form1['.fieldN .']', $label , $rules);
does not work as expected: i cannot validate. Looking into Form_validation.php library, set_rules first paramer is a string, and its value can be an array, but i can't go deeper with nesting e.g. array of array. There is a way to do this?Any hints?