Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-23T13:10:19.880Z
Answers.Text: I am trying to get errors on required fields when an entry is disabled. `$errors = $entry->getErrors()` returns an empty array in this case.
Answers.UserDisplayName: Tim Paine
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-23T14:25:22.377Z
Answers.Text: 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
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-24T12:24:08.167Z
Answers.Text: I added setting the scenario before validation, which should now give you errors for your required fields.
Answers.UserDisplayName: Ben Croker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-23T12:49:33.710Z
Answers.LastActivityDate: 2018-10-24T12:23:08.760Z
Answers.LastEditDate: 2018-10-24T12:23:08.760Z
Answers.UserDisplayName: Robin Schambach
Body: <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>
  
Tags: <plugin-development><craft3>
Title: How to validate entry in Craft 3
ThreadText: # 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
  
  ```php
  // 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.  
  
  ---
  
  