Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Validate Confirm Email in custom form

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

Page: 1
Go to End
Author Topic: 891 Views
  • Sindhura
    Avatar
    Community Member
    2 Posts

    Validate Confirm Email in custom form Link to this post

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

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Validate Confirm Email in custom form Link to this post

    @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.

    891 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.