1778 Posts in 581 Topics by 555 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 219 Views |
-
Validate Confirm Email in custom form

14 February 2013 at 10:32pm
Hi,
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);
} -
Re: Validate Confirm Email in custom form

15 February 2013 at 2:40am
@see http://doc.silverstripe.org/framework/en/topics/form-validation
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.
| 219 Views | ||
|
Page:
1
|
Go to Top |


