Hi All,
I have some form fields which can be repeated multiple multiple times within my form.
For example, the same two fields, which are repeating 5 times within my form.
I'm a little unclear on the best way to process multiple form fields data so they can be saved back into the DB.
If anyone could shed anylight on this? it would be much appriciated.
My form has a couple fields.
View:
PHP Code:
$data = array('name'=>'keyword_meta_title[]', 'id' => 'keyword_meta_title');
echo form_input($data);
$data = array('name'=>'keyword_meta_description[]', 'id' => 'keyword_meta_description');
echo form_input($data);
I'm trying to loop around the form fields and create a $data array with the relevant information for each of the fields which i will then pass into my update statement.
Controller
PHP Code:
if($this->form_validation->run() === TRUE){
// not sure if this is correct, as its only looking at one field, but should get the correct array count?
$array = $this->input->post('keyword_meta_title');
foreach($array as $arr => $k){
$data = array(
'keyword_meta_title' => $this->input->post('keyword_meta_title'),
'keyword_meta_description' => $this->input->post('keyword_meta_description')
);
$this->website_model->update_keywords($id, $data);
}
$this->alert("Website updated successfully", "success");
redirect('websites/index', 'refresh');
}
Thanks,
MoFish