Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » CheckboxField not validating with RequiredFields

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

Page: 1
Go to End
Author Topic: 1598 Views
  • Martijn
    Avatar
    Community Member
    271 Posts

    CheckboxField not validating with RequiredFields Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: CheckboxField not validating with RequiredFields Link to this post

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

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

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: CheckboxField not validating with RequiredFields Link to this post

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

    1598 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.