Yan Shuang Low
Yan Shuang Low

Reputation: 47

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
}

Upvotes: 1

Views: 177

Answers (3)

leninhasda
leninhasda

Reputation: 1730

Try this

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

Upvotes: 0

Double H
Double H

Reputation: 4160

You can use ArrayHelper

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

Upvotes: 0

Amarnasan
Amarnasan

Reputation: 15529

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
}

Upvotes: 1

Related Questions