I have not found any easy way to accomplish to simply check a Checkbox by default. That can not be that hard, so what am i missing?
You can also just set the attr attribute in the form builder buildForm method:
$builder->add('isPublic', CheckboxType::class, array( 'attr' => array('checked' => 'checked'), ));
In Symfony >= 2.3 "property_path" became "mapped".
So:
$builder->add('checkboxName', 'checkbox', array('mapped' => false, 'label' => 'customLabel', 'data' => true, // Default checked ));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With