如何在codeigniter中修改<select required =“”>到form_dropdown

时间:2017-05-29 02:55:15

标签: php codeigniter

根据Outliers在这里提出的问题,并根据Adr发布的答案 echo form_dropdown('salutation',$ salutationOptions,'','required =“required”'); 我在代码点火器的控制器中创建form_dropdown时尝试过类似的代码,我这样做 $ code = array(    'type'=&gt; '文本',    'id'=&gt; '产品代码',    'name'=&gt; '产品代码',    'class'=&gt; “形式控制”,    '必要'=&GT; '需要' ); $ form ['open'] = form_open_multipart('Mold / saveeditproduct'); $ form ['code'] = form_input($ code); $ form ['category'] = form_dropdown('category',$ category,'','id =“category”class =“form-control”required =“required”'); $ form ['submit'] = form_input($ submit); $ form ['close'] = form_close(); 我尝试运行该程序,我发现'required'属性在form_input中运行良好,但在form_dropdown中不起作用。那么,我该如何解决这个问题呢?谢谢

1 个答案:

答案 0 :(得分:2)

问题是您在下拉列表(----- Select Category -----)中为第一个选项指定的值为 0

试试这段代码:

// $data['category'] = array( array('idcategory' => 4,'categoryname' => 'new'),
//                            array('idcategory' => 2,'categoryname' => 'old'));

$data['category'] = $this->Mouldmodel->getallcategory();
$category[] = array(); 
$category[''] = '----- Select Category -----'; 
foreach($data['category'] as $dm){ 
  $category[$dm['idcategory']] = $dm['categoryname']; 
}