Validate checkbox not mapped to entity in a symfony2 form
Updated answer for Symfony 3.0:
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Validator\Constraints\IsTrue;
// ...
{
$builder->add('terms', CheckboxType::class, array('constraints'=>new IsTrue(array('message'=>'Needs to be clicked')));
}
NotBlank
validates string to be not empty. Try to use NotNull
IsTrue must also works.
Validates that a value is true. Specifically, this checks to see if the value is exactly true, exactly the integer 1, or exactly the string "1". This constraint can be applied to properties (e.g. a termsAccepted property on a registration model).