Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.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
Php 如何从yii中的禁用下拉列表中获取值?_Php_Yii_Yii2 - Fatal编程技术网

Php 如何从yii中的禁用下拉列表中获取值?

Php 如何从yii中的禁用下拉列表中获取值?,php,yii,yii2,Php,Yii,Yii2,我在我的视图中使用活动窗体,如 <?= $form->field($model, 'ishead') ->dropDownList( array( "1" => "I'm a Head", "0" => "I'm not a head" ), ['prompt'=>'-Se

我在我的视图中使用活动窗体,如

<?= $form->field($model, 'ishead')
         ->dropDownList(
                array(
                  "1" => "I'm a Head",
                  "0" => "I'm not a head"
                 ), 
                ['prompt'=>'-Select a head type-']
           )
?>
当我提交表单时,我无法获得禁用下拉值的值


这个程序对吗?或者如何做到这一点

首先在表单中创建一个隐藏字段

在下面的代码之后,只需将值指定给隐藏字段。 然后只有它会在提交后进行

$("#register-ishead").val('1');
$("#register-ishead").prop("disabled", true);
Readonly在下拉列表中不起作用。
您必须使用disabled并将数据保留在隐藏字段中。

一个棘手的方法是在提交表单之后(将数据发送到服务器之前)启用下拉列表。大概是这样的:

$(document).ready(function(){
    $("#YourFormID").submit(function(){
         $("#register-ishead").removeAttr("disabled");
         return true;
    });
});
$(document).ready(function(){
    $("#YourFormID").submit(function(){
         $("#register-ishead").removeAttr("disabled");
         return true;
    });
});