Hi there,
I'm an SS nube trying to create a form with a checkbox that the user has to check before submitting the form. I'm sure its pretty easy but nothing I've done so far seems to work. Here's what I tried so far (stripped down to the minimum for clarity):
class Test_Form extends Form {
public function __construct($controller, $name) {
$fields = new FieldSet(new ConsentField('TsAndCs', 'I agree to the Ts & Cs'));
//ACTIONS
$actions = new FieldSet(
new FormAction('submit', 'Register')
);
//VALIDATOR
$validator = new RequiredFields('TsAndCs');
parent::__construct($controller, $name, $fields, $actions, $validator);
}
}
class ConsentField extends CheckboxField {
function validate($validator) {
return $this->value == 1 ? true : false;
}
}
It appears on the form but the form submits regardless... can anyone switch on the light please?! Also how would I add javascript validation for this as well?
Many thanks
Ben