动态下拉列表正确列出项目。当表单提交时,下拉字段结果为空。

dynamic dropdown lists items correctly. When form submitted dropdown field results in null.

使用 Codeigniter 和 HMVC,我在一个模块中创建了一个动态下拉列表,并在另一个模块的表单上使用它。当表单运行时,下拉列表是正确的,您可以 select 您想要的项目。当 furm 提交时,结果为空。

public function get_stat_form()
        {
            $data['status'] = $this->stati->find();
            $this->load->view('stat_form', $data);
         }

这是下拉视图中的代码:

       <?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);
         ?>

其他模块形式的调用方式如下:

echo Modules::run('status/status/get_stat_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');

首先,检查哪个变量具有空值。 我假设你的变量 $status_id 是你的下拉列表的变量。

所以,尝试更改控制器上的变量

$status_id = $this->input->post('status');

至此

$status_id = $this->input->post('stati');