I have tried to validate inputs in my form all of them works, except checkbox. What am i doing wrong?
<div class="transactions-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'who_paid_id')->dropDownList($users)->label('Who paid') ?>
<?= $form->field($model, 'service_id')->dropDownList($services)->label('Service') ?>
<input type="hidden" id="transactions-who_paid" name="Transactions[who_paid]" >
<input type="hidden" id="transactions-service" name="Transactions[service]" >
<input type="hidden" id="transactions-amount_per_person" name="Transactions[amount_per_person]" >
<?= $form->field($model, 'amount')->textInput() ?>
<div id="transactions-who_has_to_pay_for_it_ids" inline="" aria-required="true" aria-invalid="true">
<?php foreach ($users as $key=>$value){ ?>
<label><input type="checkbox" name="Transactions[who_has_to_pay_for_it_ids][<?= $key ?>]" value="<?= $key ?>" <?php if(in_array($key, $whoHasToPay)){ echo 'CHECKED'; } ?>> <?= $value ?></label>
<?php } ?>
<label><input type="checkbox" name="Transactions[who_has_to_pay_for_it_ids][0]" value="0"> Everybody</label></div>
<?= $form->field($model, 'date_of_payment')->textInput(array('type'=>'date')) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
What I have tried:
public function rules()
{
return [
[['who_paid_id', 'service_id', 'amount', 'who_has_to_pay_for_it_ids', 'date_of_payment'], 'required'],
[['who_paid_id', 'service_id'], 'integer'],
[['amount', 'amount_per_person'], 'number'],
[['who_has_to_pay_for_it'], 'string'],
[['date_of_payment', 'creation_date'], 'safe'],
[['who_paid', 'service'], 'string', 'max' => 45],
];
}