In the database there is a field with the data type varchar. There will be different values, but you still need to make a checkbox that would send - the values ​​are Yes / No or 0/1.

Here is a checkbox

<?= $form->field($model, 'status')->checkbox([], false); ?> 

In the rules of validation rules, the type 'string' is simply specified. When sending, the status field sends null. Tell me how to implement it correctly, do we need additional validation rules?

    1 answer 1

    Try this:

     <?= $form->field($model, 'status')->checkbox(['uncheck'=>'No', 'value'=>'Yes'], false); ?> 

    In the rules we check for compliance with the value:

     ['status', 'match', 'pattern' => '/^(yes|no)$/', 'message' => 'Your message for error.'], 
    • It does not work, it is necessary even without Yes, for a simple one - the field is checked - 1, it is not checked - 0, for the time being it gives null. The problem is that in this very field I will have both textInput, checkbox and textarea - Vlad Shkuta
    • @VladShkuta Soooo, it can not be, then let's get more information about how you check the value and see whether in the Network tab in the browser when you send the form - modelfak September