gpt4 book ai didi

cakephp - 添加禁用(和选择)选项以使用表单助手选择项目

转载 作者:行者123 更新时间:2023-12-03 18:27:36 24 4
gpt4 key购买 nike

你好
我正在尝试使用表单助手将禁用选项添加到选择框中,我使用此代码生成一个额外的空字段,但我希望禁用此字段。

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, '禁用' => FALSE)));

关于cakephp - 添加禁用(和选择)选项以使用表单助手选择项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4099256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com