Hi,
I'm looking for a little guidance on the best way to loop around some form input fields.
I have a form with a few input boxes. I have used the [] on the end of the names in an attempt to get these into an array.
View
Code:
<input type="text" class="form-control" id="url[]" name="url[]" placeholder="" value="<?=set_value('url[]'); ?>" />
<input type="text" class="form-control" id="price[]" name="price[]" placeholder="199" value="<?=set_value('price[]'); ?>" />
I'm now trying to get each of the values out and save them to the database.
I assume I need a foreach loop to do this, but am not sure on the best way to do this. I have the following in my controller so far.
Controller
PHP Code:
$post_array = array(
'url' => $this->input->post('url[]'),
'price' => $this->input->post('price[]'),
'order_id' => '1'
);
$this->order_model->add($post_array);
Any help/guidance would be much appriciated!
Thanks,
MoFish