简体   繁体   English

POST方法在使用PHP的Yii2中不起作用

[英]POST method doesn't work in Yii2 using PHP

My application is using Yii2. 我的应用程序使用Yii2。 I had insert this code into one of the page: 我已将此代码插入页面之一:

Multiple Selection: <input name="multi" type="checkbox" value="selected" />&nbsp;&nbsp;'; 

I want to know whether this checkbox is been selected a not. 我想知道是否未选中此checkbox Any idea how can i do it? 知道我该怎么办吗? I had tried this method but it doesn't work: 我已经尝试过这种方法,但是它不起作用:

if($_POST['multi'] == 'selected')
{ //do sth
}

If the checkbox has been checked, it will be sent in the POST . 如果该复选框已被选中,它将在POST发送。 Otherwise, it will be not. 否则,事实并非如此。 So: 所以:

if (isset($_POST['multi'])) {
  //do stuff
}

You can use ArrayHelper 您可以使用ArrayHelper

$multi = \yii\helpers\ArrayHelper::getValue($_POST ,'multi' , null);
if($multi === 'selected'){
     //do something
}

Try this 尝试这个

if (isset($_POST['multi']) && 'selected' == $_POST['multi']) {
    //do stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM