Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » form validation on cms page

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

Page: 1
Go to End
Author Topic: 1888 Views
  • Ben_W
    Avatar
    Community Member
    80 Posts

    form validation on cms page Link to this post

    Hi, I have added three fields in a page named, FanchisePage. Pretty straight forward.

    $fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new TextField('Phone'), 'Content');
          $fields->addFieldToTab('Root.Content.Main', new EmailField('Email'), 'Content');

    what I would like to know is, how may I validate this form, when user fill in value in the back end cms area? Let's say, I need make Headline and Email as mandatory field.

    Thanks!

  • abmcr
    Avatar
    Community Member
    2 Posts

    Re: form validation on cms page Link to this post

    I am absolute beginner with Silverstripe.... and i also have this question
    How it is possible to use a validator for a field add with

    $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');

    Thank you

  • dvp
    Avatar
    Community Member
    4 Posts

    Re: form validation on cms page Link to this post

    As i know in CMSMain validators are supportted from SS 2.4.0 alpha1 by defining getCMSValidator() function in Page object.

    In prior versions you can patch CMSMain->getEditForm() function and change Form creation
    from:
    $form = new Form($this, "EditForm", $fields, $actions);
    to:
    $validator = ($record->hasMethod('getCMSValidator')) ? $record->getCMSValidator() : null;
    $form = new Form($this, "EditForm", $fields, $actions, $validator);

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