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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

form validation on cms page


Go to End


3 Posts   2520 Views

Avatar
Ben_W

Community Member, 80 Posts

16 March 2009 at 2:23pm

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

Community Member, 2 Posts

19 November 2009 at 11:18pm

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

Community Member, 6 Posts

15 December 2009 at 8:12pm

Edited: 15/12/2009 8:13pm

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