<p>It's normal behavior... <code>EntriesService-&gt;saveEntry()</code> never calls <code>validate()</code> on the model directly, but does call <code>validate()</code> on the <code>EntryRecord</code> and if there are errors, add it back to the model and return.</p>

<p>So if you want to run custom validation rules before calling <code>saveEntry</code> you'll need to do that yourself and respond accordingly.</p>

CC BY-SA 3.0
2016-04-01T11:13:21.123Z
Thanks Brad, so there is no way to combine those two validations. Overruling rules with defaults Craft or Yii validators like the one commented out (which i can't get to work), are these validated on the EntryRecord method then or still separately? Thanks in clearing things up!
Jacob
CC BY-SA 3.0
2016-04-01T15:16:08.003Z
They would be validated on the EntryRecord if that was the class you were extending.
Brad Bell
CC BY-SA 3.0
2016-03-31T22:00:47.337Z
2016-03-31T22:00:47.337Z
Brad Bell
<p>Currently i have to validate my model before saving because of some custom validation rules setted on the model which won't run when using the EntriesService saveEntry method.</p>

<p>This causes a two step validation when errors arise, first you get the custom validation errors and after that if there is still something wrong you get the "base" validation errors.</p>

<p>Is this a normal behavior?</p>

<pre><code>$model-&gt;validate();
</code></pre>

<p>After that i am saving the model like so:</p>

<pre><code>$result = craft()-&gt;entries-&gt;saveEntry($model);
</code></pre>

<p>Custom rules on model:</p>

<pre><code>public function rules()
{
    $rules = parent::rules();
    $rules[] = ['state', 'validateState'];
    $rules[] = ['vacancyId', 'validateId'];
    //$rules[] = ['vacancyId', 'numerical', 'unique' =&gt; false];
    $rules[] = ['office', 'validateOffice'];
    $rules[] = ['sector', 'validateSector'];

    return $rules;
}
</code></pre>

<p>Why are the custom validation rules not evaluated on the saveEntry method?</p>

<plugin-development><entries><entrymodel><validation><saveentry>
Model validation not run when using EntriesService saveEntry method
# Model validation not run when using EntriesService saveEntry method

(Asked by: username_0 on 2016-03-31)

Currently i have to validate my model before saving because of some custom validation rules setted on the model which won't run when using the EntriesService saveEntry method.
This causes a two step validation when errors arise, first you get the custom validation errors and after that if there is still something wrong you get the "base" validation errors.
Is this a normal behavior?
$model->validate();

After that i am saving the model like so:
$result = craft()->entries->saveEntry($model);

Custom rules on model:
public function rules()
{
    $rules = parent::rules();
    $rules[] = ['state', 'validateState'];
    $rules[] = ['vacancyId', 'validateId'];
    //$rules[] = ['vacancyId', 'numerical', 'unique' => false];
    $rules[] = ['office', 'validateOffice'];
    $rules[] = ['sector', 'validateSector'];

    return $rules;
}

Why are the custom validation rules not evaluated on the saveEntry method?

**Tags:** plugin-development, entries, entrymodel, validation, saveentry

---

## 1 answers

### Answer by username_1 on 2016-03-31. Score: 1 | Accepted answer

It's normal behavior... `EntriesService->saveEntry()` never calls `validate()` on the model directly, but does call `validate()` on the `EntryRecord` and if there are errors, add it back to the model and return.

So if you want to run custom validation rules before calling `saveEntry` you'll need to do that yourself and respond accordingly.

> **Comments:**
> **username_0**: Thanks Brad, so there is no way to combine those two validations. Overruling rules with defaults Craft or Yii validators like the one commented out (which i can't get to work), are these validated on the EntryRecord method then or still separately? Thanks in clearing things up!  
> **username_1**: They would be validated on the EntryRecord if that was the class you were extending.  

---

