Here, My html view for multiple checkbox :
Html for check box is like below
For A_I Checkbox
<input type="hidden" name="auto_number[]" id="auto_numberhidden" value="0" />
<input type="checkbox" name="auto_number[]" id="auto_number" value="1" />
For Not Display IN Form Checkbox
<input type="hidden" name="not_show_in_form[]" id="not_show_in_formhidden" value="0" />
<input type="checkbox" name="not_show_in_form[]" id="not_show_in_form" value="1" />
Here is my CI function for add table data :
if ($this->form_validation->run() == TRUE) {
$name_col = $this->input->post('name_col');
$type_col = $this->input->post('type_col');
$length_values_col = $this->input->post('length_values_col');
$index_col = $this->input->post('index_col');
$auto_number = $this->input->post('auto_number');
$not_show_in_form = $this->input->post('not_show_in_form');
$createTable = $post = array();
for ($i = 0; $i < count($name_col); $i++) {
$createTable['fields'][] = array(
'name_field' => $name_col[$i],
'type_field' => $type_col[$i],
'length_field' => $length_values_col[$i],
'index_field' => $index_col[$i],
'auto_field' => $auto_number[$i],
'not_show_in_form' => $not_show_in_form[$i]
);
}
echo '<pre>';
print_r($createTable);die;
}
When I'm submit my form, It will give me form array like :
Array
(
[fields] => Array
(
[0] => Array
(
[name_field] => id
[type_field] => INT
[length_field] => 11
[index_field] => PRIMARY
[auto_field] => 0
[not_show_in_form] => 0
)
[1] => Array
(
[name_field] => name
[type_field] => VARCHAR
[length_field] => 20
[index_field] =>
[auto_field] => 1
[not_show_in_form] => 1
)
[2] => Array
(
[name_field] => gender
[type_field] => VARCHAR
[length_field] => 10
[index_field] =>
[auto_field] => 0
[not_show_in_form] => 0
)
[3] => Array
(
[name_field] => created_date
[type_field] => DATE
[length_field] =>
[index_field] =>
[auto_field] => 0
[not_show_in_form] => 0
)
)
)
Issue:
Here, id field have two check value i.e. A_I and Not Display IN Form and created_date have only Not Display IN Form. According to my form my array like as below, But it give me above array.
Array
(
[fields] => Array
(
[0] => Array
(
[name_field] => id
[type_field] => INT
[length_field] => 11
[index_field] => PRIMARY
[auto_field] => 1
[not_show_in_form] => 1
)
[1] => Array
(
[name_field] => name
[type_field] => VARCHAR
[length_field] => 20
[index_field] =>
[auto_field] => 0
[not_show_in_form] => 0
)
[2] => Array
(
[name_field] => gender
[type_field] => VARCHAR
[length_field] => 10
[index_field] =>
[auto_field] => 0
[not_show_in_form] => 0
)
[3] => Array
(
[name_field] => created_date
[type_field] => DATE
[length_field] =>
[index_field] =>
[auto_field] => 0
[not_show_in_form] => 1
)
)
)
How can I fixed my array.
Thanks for your help.
Aucun commentaire:
Enregistrer un commentaire