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 /

Field error message in custom form template


Reply


3 Posts   391 Views

Avatar
updog

Community Member, 13 Posts

30 December 2013 at 3:33pm

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?

Avatar
Martinjj

Community Member, 12 Posts

30 December 2013 at 10:37pm

Edited: 31/12/2013 2:47am

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

Avatar
updog

Community Member, 13 Posts

31 December 2013 at 12:28pm

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