Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework2 zf2表单禁用选择选项_Zend Framework2_Zend Form2 - Fatal编程技术网

Zend framework2 zf2表单禁用选择选项

Zend framework2 zf2表单禁用选择选项,zend-framework2,zend-form2,Zend Framework2,Zend Form2,是否可以禁用select元素中的选项 我有一个带有select元素的表单,默认情况下有很多选项可用。在表单创建期间,根据从数据库检索到的信息,我想禁用某些选项 一些研究得出了一些结论 $form->get('selectElement')->setAttribute(“禁用”,数组(0,1,2)) …应该禁用前3个选项,但不幸的是没有。必须使用setAttribute()方法设置select元素的属性,而不是其选项。为此,应使用setValueOptions(): $myOptions必须是一组

是否可以禁用select元素中的选项

我有一个带有select元素的表单,默认情况下有很多选项可用。在表单创建期间,根据从数据库检索到的信息,我想禁用某些选项

一些研究得出了一些结论
$form->get('selectElement')->setAttribute(“禁用”,数组(0,1,2))

…应该禁用前3个选项,但不幸的是没有。

必须使用
setAttribute()
方法设置
select
元素的属性,而不是其选项。为此,应使用
setValueOptions()

$myOptions
必须是一组选项:

[
    [
        'label' => 'My first option',
        'disabled' => false,
        'value' => 1
    ],
    [
        'label' => '2nd option',
        'disabled' => false,
        'value' => 2
    ],
    [
        'label' => '3rd option disabled',
        'disabled' => true,
        'value' => 3
    ],
]
可能重复:
[
    [
        'label' => 'My first option',
        'disabled' => false,
        'value' => 1
    ],
    [
        'label' => '2nd option',
        'disabled' => false,
        'value' => 2
    ],
    [
        'label' => '3rd option disabled',
        'disabled' => true,
        'value' => 3
    ],
]