Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Field error message in custom form template

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

Page: 1
Go to End
Author Topic: 372 Views
  • updog
    Avatar
    Community Member
    13 Posts

    Field error message in custom form template Link to this post

    In my form processing function I have:

    $form->addErrorMessage('Email', 'Your email address is already registered in our system','bad');

    and in my template:

    $Fields.FieldByName(Email)

    I can see that the bad class has been added to the input, but how do I display an inline error message?

  • Martinjj
    Avatar
    Community Member
    12 Posts

    Re: Field error message in custom form template Link to this post

    Hello..

    Is the code that you are using your own, or is it from Arams SSbits "user registration and edit member profiles tutorial"? if it is from SSbits then this is what i had to do to get it to work (SS 3.1)

    public function submit($data, $form) {

    // Throw error if email is not unique
    if (!($data['Email']) || Member::get()->filter('Email', $data['Email'])->Count()) {
    $form->addErrorMessage('Email', 'Email in use,please use another', 'bad');

    //Set form data from submitted values
    // Session::set("FormInfo.Form_RegistrationForm.data", $data);

    return $this->redirectBack();
    }

    I had to make many changes to have the SSbits code compatible with SS3.1, if you would like the complete (working 100% code) then i have no problem zipping it and attaching to this post, if you do want the archive just holler..

    Regards
    Martin

  • updog
    Avatar
    Community Member
    13 Posts

    Re: Field error message in custom form template Link to this post

    Hi Martin,

    It is my own code. I don't have a problem with validating whether the email address exists, just with displaying the error message underneath the email field - or any other messages under their respective fields.

    This seems like something that should be very easy to do, take the laravel framework for example -http://laravel.com/docs/validation#working-with-error-messages

    If you have a custom SS template I would love to have a look at it and see if it helps.

    Thanks,

    Ash

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