<p>Every model has a <code>validate()</code> function</p>

<pre class="lang-php prettyprint-override"><code>// set the scenario to live
$entry-&gt;setScenario(Element::SCENARIO_LIVE);

// validate the model
$entry-&gt;validate();

// get the errors,
$errors = $entry-&gt;getErrors();
</code></pre>

CC BY-SA 4.0
2018-10-23T13:10:19.880Z
I am trying to get errors on required fields when an entry is disabled. `$errors = $entry->getErrors()` returns an empty array in this case.
Tim Paine
CC BY-SA 4.0
2018-10-23T14:25:22.377Z
That's because of the default behavior and scenario. Those fields are not required when the entry is disabled. You'll need to change the Scenario first or enable it otherwise `getErrors()` won't return errors since there are none
Robin Schambach
CC BY-SA 4.0
2018-10-24T12:24:08.167Z
I added setting the scenario before validation, which should now give you errors for your required fields.
Ben Croker
CC BY-SA 4.0
2018-10-23T12:49:33.710Z
2018-10-24T12:23:08.760Z
2018-10-24T12:23:08.760Z
Robin Schambach
<p>An entry could be validated by the following code in craft 2:</p>

<pre><code>craft()-&gt;content-&gt;validateContent($entry);
</code></pre>

<p>How could be the same done in Craft 3 ?</p>

<plugin-development><craft3>
How to validate entry in Craft 3
# How to validate entry in Craft 3

(Asked by: username_0 on 2018-10-23)

An entry could be validated by the following code in craft 2:
craft()->content->validateContent($entry);

How could be the same done in Craft 3 ?

**Tags:** plugin-development, craft3


---

## 1 answers

### Answer by username_1 on 2018-10-23. Score: 4 | Accepted answer

Every model has a validate() function
// set the scenario to live
$entry->setScenario(Element::SCENARIO_LIVE);

// validate the model
$entry->validate();

// get the errors,
$errors = $entry->getErrors();

> **Comments:**
> **username_0**: I am trying to get errors on required fields when an entry is disabled. `$errors = $entry->getErrors()` returns an empty array in this case.  
> **username_1**: That's because of the default behavior and scenario. Those fields are not required when the entry is disabled. You'll need to change the Scenario first or enable it otherwise `getErrors()` won't return errors since there are none  
> **username_2**: I added setting the scenario before validation, which should now give you errors for your required fields.  

---

