1
votes

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?

2

2 Answers

1
votes

I'm not sure if this is what you are looking for, but I do something like this:

public function MyFormAction(){
    //do something
    if(//something is wrong){
        $this->MyErrorMessage = 'Something is wrong';
        return $this->renderWith(array('MyFormPage', 'Page'));
    }
}

And then in the template I can put where I want:

<% if $MyErrorMessage %>
<p class='bad'>$MyErrorMessage</p>
<% end_if %>
1
votes

You have to only add bellow in your $form->addErrorMessage('Email', 'Your email address is already registered in our system','bad');

return $this->redirectBack();

I'm using this on all my forms. Be sure to use this inside a Submit function. You will be redirected to your form with the error message below the field Email. You dont need to create a custom template for this.