I'm facing a problem regarding general form validation in codeigniter. In my case, the fields are posted in array $m_data = json_decode($this->input->post('data')); and needs to be validated before sending them to the model. see this example
$m_data = json_decode($this->input->post('data'));
$validation_rules = array(
$m_data['title'] => 'trim|xss_clean|required|max_length[50]',
$m_data['code'] => 'trim|xss_clean|required|max_length[50]'
);
foreach ($validation_rules as $key => $value){
$this->form_validation->set_rules($key,$key,$value);
}
if ($this->form_validation->run()) {
foreach ($validation_rules as $key => $value){
$m_data[$key] = $this->form_validation->set_value($key);
}
// do insertion
}
the problem here that form validation will take each field separately as posted data using the 'key' of value posted and run the rules over it. I tried to create custom validation that receive an array of fields as input but I had no clue how to do this.
can you help me figuring a way to validate the array content using CI form validation, any input is appreciated