Codigniter无法选择下拉列表的值

时间:2016-04-07 05:34:14

标签: php codeigniter

<div class="col-md-11 col-sm-10 col-xs-12 pd-le0 pd-ri0">
    <div class="col-md-6 col-sm-6 col-xs-12">   
        <div class="form-group ">
            <label class="control-label col-md-4 col-sm-4 col-sm-12" title="Which Key Person does the following information apply to?">Key ID</label>
            <div class="col-md-8 col-sm-8 col-xs-12">
              <?php /*Previos Entries :- $ValueTax['Person_id']*/
                     //print_r ($optionkey);exit;
                    echo form_dropdown('key_id['.$key.']', $optionkey,"",array('class'=>'form-control KeypeopleId','id'=>'Person_id['.$key.']','onchange'=>'addKeypeople(this.options[this.selectedIndex].text)'));
             ?>
             </div>
        </div>

v  您好,我在上面的代码中遇到问题。  问题是当我要选择下拉列表时,表单没有出现,并且在点击下拉列表后我无法在表单中前进

&#34; $ option键&#34;来自这里

<?php
$options = array(
  '0'=>'No',
  '1'=>'Yes',
);
$option="";
foreach($options as $key=>$value){
    $option .="<option value=".$key.">".$value."</option>";
}
$optionkeys="";
foreach($optionkey as $key=>$value){
    $optionkeys .="<option value=".$key.">".$value."</option>";
}

&GT?;  这是我的模型从哪里获取Keyid

function get_key_people($user_id){
    //print_r ($user_id);exit;
    $this->db->select('Key_Person_ID,Key_ID');
    $this->db->from('key_people'); 
    $this->db->where('user_FK',$user_id); 
    $this->db->where('is_delete',0);
    $result=$this->db->get()->result_array();
    $ar=array(''=>"Select",'ADDNEW'=>"ADD NEW");
    foreach($result as $key=>$value){
        $ar[$value['Key_Person_ID']]=$value['Key_ID'];
    }
    return $ar;
}

知道这里发生了什么或如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您不需要自己处理$ optionkey。在CI中,form_dropdown函数会自动添加<select></select><option></option>标记。

form_dropdown([$name = ''[, $options = array()[, $selected = array()[, $extra = '']]]])
$name (string) -- Field name
$options (array) -- An associative array of options to be listed
$selected (array) -- List of fields to mark with the selected attribute
$extra (mixed) -- Extra attributes to be added to the tag either as an array or a literal string

此函数位于\ system \ helpers \ form_helper.php中 手册:Link to a Codepen of the below code