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

Validate Confirm Email in custom form


2 Posts   910 Views


14 February 2013 at 10:32pm Community Member, 2 Posts


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


15 February 2013 at 2:40am Community Member, 215 Posts


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.