Hi i am submitting a form fields with same name
Form
<form role="form" class="m-t-20" method="post"
action='<?php echo base_url();?>save'>
<tbody>
<tr>
<td>
<input type="text" name="chemistname[]" id="chemistname" class="form-control m-b-10">
</td>
<td>
<input type="text" name="chemist_mobile[]" id="chemist_mobile" class="form-control m-b-10" pattern=".{10,10}" title="Enter 10 digit Mobile Number" onkeypress="return isNumber(event)">
</td>
<td>
<select class="form-control" name="typeofchemist[]" id="typeofchemist">
<option>Select Type of Chemist</option>
<option value="Attached">Attached</option>
<option value="Floating">Floating</option>
<option value="Institution">Institution</option>
</select>
</td>
<td>
<input type="text" name="realtion[]" id="realtion" class="form-control m-b-10">
</td>
</tr>
<tr>
<td>
<input type="text" name="chemistname[]" id="chemistname" class="form-control m-b-10">
</td>
<td>
<input type="text" name="chemist_mobile[]" id="chemist_mobile" class="form-control m-b-10" pattern=".{10,10}" title="Enter 10 digit Mobile Number" onkeypress="return isNumber(event)">
</td>
<td>
<select class="form-control" name="typeofchemist[]" id="typeofchemist">
<option>Select Type of Chemist</option>
<option value="Attached">Attached</option>
<option value="Floating">Floating</option>
<option value="Institution">Institution</option>
</select>
</td>
<td>
<input type="text" name="realtion[]" id="realtion" class="form-control m-b-10">
</td>
</tr>
</tbody>
</form>
Controller
public function user_registration()
{
$objDate = new DateTime();
$employee_id = $this->session->userdata('employee_id');
$usercode =$this->User_model->User_code();
$form_data = $this->input->post();
$args = array('chemistname' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY));
$chemistname = filter_input_array(INPUT_POST,$args);
$args = array('chemist_mobile' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY));
$chemist_mobile = filter_input_array(INPUT_POST,$args);
$args = array('typeofchemist' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY));
$typeofchemist = filter_input_array(INPUT_POST,$args);
$args = array('realtion' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY));
$realtiont = filter_input_array(INPUT_POST,$args);
//You may need to check this part
$newArray=array();
$i=0;
foreach($chemistname as $rowChemistName){
$newArray[$i]['chemist_name']=$rowChemistName;
$newArray[$i]['chemist_mobile']=$chemist_mobile[$i];
$newArray[$i]['typeofchemist']=$typeofchemist[$i];
$newArray[$i]['realtion']=$realtiont[$i];
$i++;
}
echo'<pre>';print_r($chemistname);
echo'<pre>';print_r($newArray);exit;
}
I need to get these inputs as single array and to be inserted as individual rows in the database
How should i get those values into an array by using foreach loop or any other condition to get the data as an array
Am using codeigniter-3, am using post method and am calling the controller and parsing the data and inserting into database
I have same three scenarios of this kind, after form submission the data is not pushed into newArray