Using Codeigniter and HMVC, I have created a dynamic dropdown in a module and use it on a form in another module. when the form runns, the dropdown list is correct and you can select the item you want. When the furm sbmits the result is null.
public function get_stat_form()
{
$data['status'] = $this->stati->find();
$this->load->view('stat_form', $data);
}
Here is code from dropdown view:
<?php
$attr = array(
'name' => 'stati',
'class' => 'form-control m-top-10',
);
$drop = array('' => 'Select a Status');
foreach($status as $stat):
$drop[$stat['status_id']] = $stat['status_name'];
endforeach;
echo form_dropdown($attr, $drop);
?>
Here is how it is called in the other module form:
echo Modules::run('status/status/get_stat_form');
Here is the controller function for the form:
$project = $this->input->post('project');
$status_id = $this->input->post('status');
$fn1 = $this->input->post('fn1');
$ln1 = $this->input->post('ln1');
$fn2 = $this->input->post('fn2');
$ln2 = $this->input->post('ln2');
$oaddress = $this->input->post('oaddress');
$ocity = $this->input->post('ocity');
$ostate = $this->input->post('ostate');
$ozip = $this->input->post('ozip');
$ohomephone = $this->input->post('ohomephone');
$ocellphone = $this->input->post('ocellphone');
$oemail1 = $this->input->post('oemail1');
$project_data = array(
'project' => $project,
'status_id' => $status_id,
'fn1' => $fn1,
'ln1' => $ln1,
'fn2' => $fn2,
'ln2'=> $ln2,
'oaddress' => $oaddress,
'ocity' => $ocity,
'ostate' => $ostate,
'ozip' => $ozip,
'ohomephone' => $ohomephone,
'ocellphone' => $ocellphone,
'oemail1' => $oemail1,
);
$data['project_data'] = $this->project->save($project_data);
if(!empty($data['project_data']))
{
$this->session->set_flashdata('ProjectAdded',
'You have successfully added a project..!!');
redirect('project_list');
first, check which variable has a null value.
i assume your variable $status_id
is variable for your dropdown.
so, try to change your variable on your controller
$status_id = $this->input->post('status');
to this
$status_id = $this->input->post('stati');