Reputation: 47
My application is using Yii2. I had insert this code into one of the page:
Multiple Selection: <input name="multi" type="checkbox" value="selected" /> ';
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
Reputation: 1730
Try this
if (isset($_POST['multi']) && 'selected' == $_POST['multi']) {
//do stuff
}
Upvotes: 0
Reputation: 4160
You can use ArrayHelper
$multi = \yii\helpers\ArrayHelper::getValue($_POST ,'multi' , null);
if($multi === 'selected'){
//do something
}
Upvotes: 0
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