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
}
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.