<p>Actually, onAfterElementSave doesn't get called at all when saving a draft, so there's nothing to worry about.</p>

<p>When you load a draft in the CP, your field type will be passed in a $value based on the POST data for the field back when the draft was last saved (which is the same thing that happens when saving an entry fails due to validation errors).</p>

CC BY-SA 3.0
2014-10-23T16:25:00.183Z
For some reason that method is being called in my plugin when I save the entry as a draft. I am using "Craft Pro 2.2.2596".
a-am
CC BY-SA 3.0
2014-10-24T12:23:10.820Z
@aran Is that for a brand new entry? In that case it will get called, but it won't matter because the entry will be disabled and there's no chance you'll be overwriting existing data for the entry.
Brandon Kelly
CC BY-SA 3.0
2014-10-23T16:16:39.307Z
2014-10-23T16:16:39.307Z
Brandon Kelly
<p>Is there a way to detect if a entry is being saved as a draft vs being published so when onAfterElementSave is called, so I don't save data to the database when it is a draft.</p>

<plugin-development>
When onAfterElementSave is called check for save as draft or publishing?
# When onAfterElementSave is called check for save as draft or publishing?

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

Is there a way to detect if a entry is being saved as a draft vs being published so when onAfterElementSave is called, so I don't save data to the database when it is a draft.

**Tags:** plugin-development

---

## 1 answers

### Answer by username_1 on 2014-10-23. Score: 1 | Accepted answer

Actually, onAfterElementSave doesn't get called at all when saving a draft, so there's nothing to worry about.

When you load a draft in the CP, your field type will be passed in a $value based on the POST data for the field back when the draft was last saved (which is the same thing that happens when saving an entry fails due to validation errors).

> **Comments:**
> **username_0**: For some reason that method is being called in my plugin when I save the entry as a draft. I am using "Craft Pro 2.2.2596".  
> **username_1**: @aran Is that for a brand new entry? In that case it will get called, but it won't matter because the entry will be disabled and there's no chance you'll be overwriting existing data for the entry.  

---

