Jump to:

1999 Posts in 1408 Topics by 613 members

Form Questions

SilverStripe Forums » Form Questions » all fields are Validating as email address

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

Page: 1
Go to End
Author Topic: 681 Views
  • merrick_sd
    Avatar
    Community Member
    94 Posts

    all fields are Validating as email address Link to this post

    I have added a contact form to a page but all fields are validating with "Please enter an email address."

    Obviously I must be missing something

    page.php +++++++++++++++++++++

    class Page_Controller extends ContentController {
    public function ValuationForm()
    {
    return new ValuationForm($this,'ValuationForm');
    }

    }

    ++++++++++++++++++++++++++++

    ValuationForm.php
    +++++++++++++++

    class ValuationForm extends Form {

    function __construct($controller, $name) {
    $fields = new FieldSet(
    new TextField('Name', 'Name'),
           new EmailField('Postcode', 'Postcode'),
    new EmailField('Email', 'Email'),
           new EmailField('Telephone', 'Telephone')
       
    );

    $actions = new FieldSet(
    new FormAction('submit', 'Submit')
    );
       
       
       
        // Create validator
    $validator = new RequiredFields('Email');

        parent::__construct($controller, $name, $fields, $actions, $validator);
    }

    function forTemplate() {
    return $this->renderWith(array(
    $this->class,
    'Form'
    ));
    }

    function submit($data, $form) {
    $valuation = new Valuation();
    $form->saveInto($valuation);
    //$valuation->JobCategoryID = $this-dataRecord->ID;
    $valuation->write();
    $form->sessionMessage('Form successfully submitted', 'good' );
    Director::redirectBack();
    return;

    // do stuff here
    }

    }
    ++++++++++++++++++++++++++++++++

  • merrick_sd
    Avatar
    Community Member
    94 Posts

    Re: all fields are Validating as email address Link to this post

    all that and its staring me in the face

    new EmailField('Postcode', 'Postcode'), should be TextField('Postcode', 'Postcode')

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