I have array of Krajee SwitchInputs, when everyone of SwitchInput is off, it returns nothing.
SwitchInput::widget([
'name' => 'work_time[]',
'value' => 1,
}
This should be expected behavior (empty checkboxes are not considered "successful") and has nothing to do with the actual kartik-widget. In the background the widget uses a regular checkbox.
To save overhead, empty checkboxes won't transmit "0". So when you have more than one and all are off, nothing will be transmitted. However this is no problem as you know when all are missing, all are off!
You can find a lot of similar questions here, like this one for example, explaining the same thing. Don't worry too much, as it is quite simple:
If you still want a workaround, you can find one here
The following code will respect the types when comparing. Normally you would use either a boolean value or 1 and 0 as integers. Both work perfectly, but the boolean-way is better, as you are then not only able to use the equal-operator ==
but also the identical-operator ===
.
$myCheckboxVal = isset(Yii::$app->request->post('my_checkbox')) ? true : false;
Thanks, I solved.
$value=isset($_POST['day_check']) ? '1' : '0';