S
S
Snewer2016-06-30 14:52:00
Yii
Snewer, 2016-06-30 14:52:00

How to check if a checkbox is checked in yii2?

Hello!
How can I set a rule that requires that some checkbox ("acceptRules") be checked?
Now I'm using the IN validator with valid values ​​[1].
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Snewer, 2016-06-30
@Snewer

I solved it like this:
['checkbox', 'required', 'requiredValue' => 1]

D
Dmitry Kim, 2016-06-30
@kimono

Extended version:

[['is_checked'], 'required'],
  [['is_checked'], 'boolean'],
  [['is_checked'], 'default', 'value' => true],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question