<blockquote>
  <p>Is this something that can be done with the Craft page when saving an entry?</p>
</blockquote>

<p>In 2.2, there isn't an easy way.  In the upcoming 2.3 release, we added a <code>$performAction</code> property to the event, so your can do something like:</p>

<pre><code>$entry-&gt;addError('attribute', 'MyErrorMessage');
$event-&gt;performAction = false;
</code></pre>

<p>And Craft will not save the entry and return to the edit entry page to display any validation errors.</p>

<p>You should post your second question as an entirely new question.</p>

CC BY-SA 3.0
2014-11-28T16:43:56.970Z
Ok, many thanks. Any news on when 2.3 will be available?
Neil Young
CC BY-SA 3.0
2014-11-28T16:44:44.923Z
Closer than you think!
Brad Bell
CC BY-SA 3.0
2014-11-28T16:46:34.250Z
Good stuff! :-)
Neil Young
CC BY-SA 3.0
2014-12-11T15:04:57.733Z
I have managed to get the update installed and have added your code above but I still don't seem to be able to add custom error messages. Although the performAction flag does seem to stop the entry from saving. Any idea of how I can get your code above to work?
Neil Young
CC BY-SA 3.0
2015-01-20T12:51:52.440Z
@NeilYoung try `$event->params['entry']->addError('MyFieldHandle', 'MyErrorMessage');`
carlcs
CC BY-SA 3.0
2014-11-28T16:41:04.143Z
2014-11-28T16:41:04.143Z
Brad Bell
<p>I am new to Craft but loving its ease of use so far.</p>

<p>I am having a problem however when setting up a plugin to display an error to the user when using the onBeforeSaveEntry hook when a user saves an entry. I am looking to determine the value of a field and then take the user back to the entry page and display an error to the user based on a certain selection. Is this something that can be done with the Craft page when saving an entry?</p>

<plugin-development>
Displaying Error onBeforeSaveEntry
# Displaying Error onBeforeSaveEntry

(Asked by: username_0 on 2014-11-28)

I am new to Craft but loving its ease of use so far.

I am having a problem however when setting up a plugin to display an error to the user when using the onBeforeSaveEntry hook when a user saves an entry. I am looking to determine the value of a field and then take the user back to the entry page and display an error to the user based on a certain selection. Is this something that can be done with the Craft page when saving an entry?

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2014-11-28. Score: 0 | Accepted answer

Is this something that can be done with the Craft page when saving an entry?

In 2.2, there isn't an easy way.  In the upcoming 2.3 release, we added a $performAction property to the event, so your can do something like:
$entry->addError('attribute', 'MyErrorMessage');
$event->performAction = false;

And Craft will not save the entry and return to the edit entry page to display any validation errors.
You should post your second question as an entirely new question.

> **Comments:**
> **username_0**: Ok, many thanks. Any news on when 2.3 will be available?  
> **username_1**: Closer than you think!  
> **username_0**: Good stuff! :-)  
> **username_0**: I have managed to get the update installed and have added your code above but I still don't seem to be able to add custom error messages. Although the performAction flag does seem to stop the entry from saving. Any idea of how I can get your code above to work?  
> **username_2**: @NeilYoung try `$event->params['entry']->addError('MyFieldHandle', 'MyErrorMessage');`  

---

