Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

CheckboxField not validating with RequiredFields

Go to End

3 Posts   1968 Views


Community Member, 271 Posts

2 October 2009 at 6:21am

Edited: 02/10/2009 6:22am

Before I start to use jquery for form validation, I wonder if I could user RequiredFields to check if a CheckboxField is selected .
The next code is not validating the CheckboxField :

function SubscriptionForm() {
		$condition =FormPage::ConditionDetails();
		$url = $condition->URLSegment;
		$fields = new FieldSet(
			new HiddenField("Subject", "Subject", $this->CF_Title),
			new TextField("Name", "Naam"),
			new CheckboxField("CheckThis","Ckeck this box")

		$actions = new FieldSet(
					new FormAction('SendSubscriptionForm', 'Send')

		$validator = new RequiredFields('Name','CheckThis');
		$form =  new Form($this, "SubscriptionForm", $fields, $actions, $validator); 
		return $form;

Seems ok, but maybe i missed something.

Thanks in advance..


Forum Moderator, 5523 Posts

2 October 2009 at 4:30pm

RequiredFields needs to be passed an array of fieldnames, not a string

new RequiredFields(array('Name', 'CheckThis'));


Community Member, 271 Posts

3 October 2009 at 12:25am

You replied before I edited the post, but you were right about the typo.

I noticed that the checkboxes do validate serverside after form submission, but not onClick with the Textfields.

However, I can live with it for the moment...