Answer the question
In order to leave comments, you need to log in
Yii2: checkbox values not being sent?
There are checkboxes on yii2 created via ActiveForm:
<?= $form->field($model, 'agency_full', [
'template' => '{input}{label}',
'options' => [
'class' => 'checkbox-group'
]
])->checkbox(['class' => 'checkbox'], false)->label( 'Агентство полного цикла', ['class' => 'for-checkbox']); ?>
<?= $form->field($model, 'design_studio', [
'template' => '{input}{label}',
'options' => [
'class' => 'checkbox-group'
]
])->checkbox(['class' => 'checkbox'], false)->label( 'Дизайн-студия', ['class' => 'for-checkbox']); ?>
<div class="checkbox-group field-signupform-agency_full">
<input type="hidden" name="SignupForm[agency_full]" value="0">
<input type="checkbox" id="signupform-agency_full" class="checkbox" name="SignupForm[agency_full]" value="1">
<label class="for-checkbox" for="signupform-agency_full">Агентство полного цикла</label>
</div>
class SignupForm extends Model
{
...
public $agency_full;
public $design_studio;
...
public function signup()
{
if (!$this->validate()) {
return null;
}
$user = new User();
...
$user->agency_full = $this->agency_full;
$user->design_studio = $this->design_studio;
...
return $user->save() ? $user : null;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question