<p>You're correct. Craft will <em>not</em> run validation upon saving disabled elements.</p>

<p>This is not a bug – it's just designed that way (as far as I can tell from looking at the relevant source code in the <a href="https://buildwithcraft.com/classreference/services/ElementsService#saveElement-detail" rel="nofollow">ElementsService</a>).</p>

<p><strong>As for a workaround – you'll need a plugin</strong>.</p>

<p>This is the easiest approach I can think of:</p>

<ol>
<li>Listen for the <code>entries.onBeforeSaveEntry</code> event</li>
<li>In the event handler, validate the entry model manually, if the entry is disabled</li>
<li>If validation fails, add error messages to the model and set the <code>$event</code> object's <code>performAction</code> attribute to false</li>
</ol>

<p><em>This should stop the entry from going through, and should also display any error messages in your form:</em></p>

<pre><code>craft()-&gt;on('entries.beforeSaveEntry',function(){
    $entry = $event-&gt;params['entry'];
    if(!$entry-&gt;enabled &amp;&amp; !craft()-&gt;content-&gt;validateContent($entry))
    {
        $entry-&gt;addErrors($entry-&gt;getContent()-&gt;getErrors());
        $event-&gt;performAction = false;
    }
    return $event;
});
</code></pre>

<p>Anyway, since I wanted to test the above before responding here, I wrote the plugin. It seems to do the job, so hopefully it'll help you out!</p>

<p><a href="https://github.com/mmikkel/AlwaysValidate-Craft" rel="nofollow">https://github.com/mmikkel/AlwaysValidate-Craft</a></p>

CC BY-SA 3.0
2015-05-20T08:30:26.030Z
thanks for the advice and the plugin.Quick question what are you pointing the action to on the frontend form to as currently I'm getting a page not found error. Cheers
Lettie
CC BY-SA 3.0
2015-05-20T08:33:41.990Z
In testing, I just copy pasted the Entry Form example from the official docs, so the action is ```entries/saveEntry```. Do you get a 404 without the plugin? What do you have for your ```redirect``` value?
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-05-20T08:42:24.063Z
sorry yep that sorted it was pointing at the plugin rather than entries. Thanks so much for your help. Cheers
Lettie
CC BY-SA 3.0
2015-05-20T08:43:00.130Z
No worries, @Lettie – happy you got it sorted!
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-05-20T08:48:01.087Z
Ahh I spoke too soon. It is validating now but it is also marking the entry as enabled. This is not what I require I need it to remain disabled until an admin has reviewed it. Is there a code snippet to add to make sure it does not enable the entry?
Lettie
CC BY-SA 3.0
2015-05-20T08:53:21.377Z
The plugin will definetely not mark the entry as enabled, so there must be something else in your code going wrong. Have you tried adding ```<input type="hidden" name="enabled" value="0">``` to your form?
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-05-20T08:59:30.940Z
Perfect @mmikkel panic over. Thanks again.
Lettie
CC BY-SA 3.0
2015-05-19T21:49:26.480Z
2015-05-19T22:28:33.047Z
2015-05-19T22:28:33.047Z
Mats Mikkel Rummelhoff
<p>I have a front end form based on the entry form example provided by craft documentation which allows logged in users to submit an entry to a specific section. Form validation is not working in that required fields are not being picked up on submission. So if the field is empty it still submits the form.</p>

<p>I have the user group set up so users are not able to use the CP or submit live entries so the entry is sent through as disabled so that the admin users can monitor entries before enabling them.</p>

<p>Am I correct in thinking that because the entry is being saved as disabled that craft does not validate the post data? If this is correct what is the work around as I do not want users to be able to post live entries.</p>

<p>Cheers</p>

<entries><form><validation>
Entry Form Validation on Front End Form
# Entry Form Validation on Front End Form

(Asked by: username_0 on 2015-05-19)

I have a front end form based on the entry form example provided by craft documentation which allows logged in users to submit an entry to a specific section. Form validation is not working in that required fields are not being picked up on submission. So if the field is empty it still submits the form.

I have the user group set up so users are not able to use the CP or submit live entries so the entry is sent through as disabled so that the admin users can monitor entries before enabling them.

Am I correct in thinking that because the entry is being saved as disabled that craft does not validate the post data? If this is correct what is the work around as I do not want users to be able to post live entries.

Cheers

**Tags:** entries, form, validation


---

## 1 answers

### Answer by username_1 on 2015-05-19. Score: 2 | Accepted answer

You're correct. Craft will not run validation upon saving disabled elements.
This is not a bug – it's just designed that way (as far as I can tell from looking at the relevant source code in the ElementsService).
As for a workaround – you'll need a plugin.
This is the easiest approach I can think of:

Listen for the entries.onBeforeSaveEntry event
In the event handler, validate the entry model manually, if the entry is disabled
If validation fails, add error messages to the model and set the $event object's performAction attribute to false

This should stop the entry from going through, and should also display any error messages in your form:
craft()->on('entries.beforeSaveEntry',function(){
    $entry = $event->params['entry'];
    if(!$entry->enabled && !craft()->content->validateContent($entry))
    {
        $entry->addErrors($entry->getContent()->getErrors());
        $event->performAction = false;
    }
    return $event;
});

Anyway, since I wanted to test the above before responding here, I wrote the plugin. It seems to do the job, so hopefully it'll help you out!
https://github.com/mmikkel/AlwaysValidate-Craft

> **Comments:**
> **username_0**: thanks for the advice and the plugin.Quick question what are you pointing the action to on the frontend form to as currently I'm getting a page not found error. Cheers  
> **username_1**: In testing, I just copy pasted the Entry Form example from the official docs, so the action is ```entries/saveEntry```. Do you get a 404 without the plugin? What do you have for your ```redirect``` value?  
> **username_0**: sorry yep that sorted it was pointing at the plugin rather than entries. Thanks so much for your help. Cheers  
> **username_1**: No worries, @username_0 – happy you got it sorted!  
> **username_0**: Ahh I spoke too soon. It is validating now but it is also marking the entry as enabled. This is not what I require I need it to remain disabled until an admin has reviewed it. Is there a code snippet to add to make sure it does not enable the entry?  
> **username_1**: The plugin will definetely not mark the entry as enabled, so there must be something else in your code going wrong. Have you tried adding ```<input type="hidden" name="enabled" value="0">``` to your form?  
> **username_0**: Perfect @mmikkel panic over. Thanks again.  

---

