form_dropdown()没有采用"名称" codeigniter中的属性

时间:2016-07-01 13:41:06

标签: codeigniter post form-helpers

我正在使用form助手类在codeigniter中创建表单。

但使用'form_dropdown("medium_type",$medium_type,"Select Medium")'并未使用name属性,因此表单验证在发布后无效。

任何人都可以告诉我如何将名称传递给元素。

function controller(){
  $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $this->data['medium_type']  = $this->field_enums('notifications', 'medium_type');
             $this->data['user_type'] = $this->field_enums('notifications', 'user_type');
                            $this->form_validation->set_rules('medium_type', 'Medium Type', 'required');

            if ($this->form_validation->run() == FALSE)
            {
                    $this->load->view('admin/notifications', $this->data);
            }
            else
            {
                    $data = array(
                    'title' => $this->input->post('title'),
                    'medium_type' => $this->input->post('mediun_type'),
                    );
                    $this->notifications_m->insert($data);

            }
            $this->load->view('admin/notifications', $this->data);
}

表单代码 `                                                                                                                                               标题                                                            

                        <div class="input-field col s12 m6 l6 margin-bottom-10px">
                          <?php echo form_dropdown("medium_type",$medium_type);?>
                          <label for="medium_tyoe">Medium Type</label>
                          <?php echo form_error('medium_type'); ?>
                        </div>

                    <div class="input-field col s12 m12 l12 margin-bottom-10px">
                          <?php echo $this->ckeditor->editor("content");?>
                          <?php echo form_error('content'); ?>
                        </div>

                        <div class="btn waves-effect waves-light col s8 m4 l4 offset-m4 offset-l4 offset-s2 ">
                          <?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
                    <i class="material-icons right">send</i>
                        </div>
                      </div>
                    </div>
                <?php echo form_close();?>`

1 个答案:

答案 0 :(得分:1)

格式

$options = array(
        'option'         => 'Name',
        'option2'         => 'Name2',
);

echo form_dropdown('medium_type', $options, 'option2');
echo form_error('medium_type');  # to show error

在控制器中

$this->form_validation->set_rules('medium_type', 'Medium Type', 'required');

if ($this->form_validation->run() == FALSE)
{
    # load the form view
}
else
{
    # Validation  pass
    $medium_type = $this->input->post('medium_type');

    echo $medium_type ;
}