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

Validate Confirm Email in custom form

Go to End

2 Posts   2105 Views


Community Member, 2 Posts

14 February 2013 at 10:32pm


How do you validate a confirm email field in a custom email form? Pasted below is the code that I am using.

function ContactForm() {
// Create fields

$fields = new FieldSet(
new TextField('Name', 'Name*'),
new NumericField('Number', 'Number in Party*'),
new DropdownField('Time', 'Preferred Time', array(
'12:30pm' => '12:30pm',
'1:00pm' => '1:00pm',
'1:30pm' => '1:30pm'
new TextField('Telephone', 'Contact number*'),
new EmailField('Email', 'Email address*'),
new EmailField('CEmail', 'Confirm email address*'),

// Create action
$actions = new FieldSet(
new FormAction('SendContactForm', 'Send')

// Create Validators
$validator = new RequiredFields('Name', ,'Telephone', 'Email');

return new Form($this, 'ContactForm', $fields, $actions, $validator);


Community Member, 344 Posts

15 February 2013 at 2:40am


Either you check both emails in the SendContactForm method and redirect back on error. Or you subclass RequiredFields.

My favorite is subclassing, because the action method should not be called unless the form is properly validated and subclassing works for ModelAdmin too.