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

CheckboxField not validating with RequiredFields


Reply

3 Posts   1610 Views

Avatar
Martijn

2 October 2009 at 6:21am (Last edited: 2 October 2009 6:22am), Community Member, 271 Posts

Hi,
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..

Avatar
Willr

2 October 2009 at 4:30pm Forum Moderator, 5511 Posts

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

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

Avatar
Martijn

3 October 2009 at 12:25am Community Member, 271 Posts

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...