Reputation: 155
I have the following:
<form method="POST" action="<?php echo site_url('admin/updateCoursesIn'); ?>">
<input type="text" value="1" name="values">
<input type="text" value="2" name="values">
<input type="text" value="3" name="values">
<input type="submit" value="Submit">
</form>
Function in codeigniter:
public function updateCoursesIn($from = "") {
$data['value'] = json_encode($this->input->post('values'));
$this->db->where('key', 'courses');
$this->db->update('frontend_settings', $data);
}
I need to save these values via codeigniter in json format, like this:
["1","2","3"]
The function I created is not saving as I need it.
Upvotes: 0
Views: 241
Reputation: 54841
To make values
array, add []
to name
attribute:
<input type="text" value="1" name="values[]">
<input type="text" value="2" name="values[]">
With such naming $this->input->post('values')
will be an array and will be correctly encoded to json.
Upvotes: 1