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

form validation on cms page


Reply

3 Posts   2008 Views

Avatar
Ben_W

16 March 2009 at 2:23pm Community Member, 80 Posts

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!

Avatar
abmcr

19 November 2009 at 11:18pm Community Member, 2 Posts

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

Avatar
dvp

15 December 2009 at 8:12pm (Last edited: 15 December 2009 8:13pm), Community Member, 4 Posts

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);