cakephp – 添加禁用(和选中)选项以选择带有表单助手的项目
发布时间:2020-12-13 22:13:11 所属栏目:PHP教程 来源:网络整理
导读:嗨 我正在尝试使用表单帮助器向选择框添加禁用选项我使用此代码生成一个额外的空字段,但我希望禁用此字段. echo $this-Form-input('User.usertype_id',array('type'='select','empty'='usertype'); 这会产生: div class="input select" label for="UserUser
嗨
我正在尝试使用表单帮助器向选择框添加禁用选项我使用此代码生成一个额外的空字段,但我希望禁用此字段. echo $this->Form->input('User.usertype_id',array('type'=>'select','empty'=>'usertype'); 这会产生: <div class="input select"> <label for="UserUsertypeId">Usertype</label> <select name="data[User][usertype_id]" id="UserUsertypeId"> <option value="">usertype</option> <option value="1">athlete</option> <option value="2">trainer</option> </select> </div> 但我想要这个: <div class="input select"> <label for="UserUsertypeId">Usertype</label> <select name="data[User][usertype_id]" id="UserUsertypeId"> <option value="" disabled="disabled" selected="selected">usertype</option> <option value="1">athlete</option> <option value="2">trainer</option> </select> </div> 有没有办法简单地做到这一点,或者我应该只使用一些js? 解决方法
如果您事先知道这些选项,则可以构建要在选择菜单中使用的$options数组.这应该给你你想要的东西:
$options = array( array( 'name' => 'usertype','value' => '','disabled' => TRUE,'selected' => TRUE ),'athlete','trainer' ); echo $this->Form->input('User.usertype_id',array('type' => 'select','options' => $options)); 或者这可能有用,但我还没有测试过: ????echo $this-> Form-> input(‘User.usertype_id’,array(‘type’=>’select’,’empty’=> array(‘text’=>’usertype’,’selected) ‘=> TRUE,’disabled’=> FALSE))); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |