简体   繁体   中英

POST method doesn't work in Yii2 using PHP

My application is using 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. 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 . Otherwise, it will be not. So:

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

You can use 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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