<p>This will return the content for the specific element instance you're on:</p>

<pre><code>$this-&gt;element-&gt;getContent()
</code></pre>

<p>And from there you can do your additional content processing.</p>

<p>When you're ready so save it, you can call:</p>

<pre><code>craft()-&gt;content-&gt;saveContent($this-&gt;element);
</code></pre>

<p>There are several examples in <code>craft/app/fieldtypes</code> folder where Craft's native field types do additional processing like this.</p>

CC BY-SA 3.0
2014-08-13T21:41:15.810Z
So if I update a property on the `ContentModel`, how does that data get saved to the db? When I update my property, the new data isn't saved to the db and you can't call `save()` on models.
Justin Kimbrell
CC BY-SA 3.0
2014-08-13T21:58:14.173Z
I figured it out. I just ran the following code to save the content. `craft()->content->saveContent($this->element);` If there is a better way, let me know. If not, may be helpful to update your answer with that code and I'll mark it as correct.
Justin Kimbrell
CC BY-SA 3.0
2014-08-13T22:09:21.950Z
That's the way... updated!
Brad Bell
CC BY-SA 3.0
2014-08-13T21:14:51.087Z
2014-08-13T22:08:50.430Z
2014-08-13T22:08:50.430Z
Brad Bell
<p>I am building a field type for Craft that needs to do additional processing to the saved data once the element id is available. For this reason, the <code>prepValueFromPost()</code> method won't work, since the element id isn't available yet.</p>

<p>So how to update the content of the current element from the <code>onAfterElementSave()</code> method?</p>

<plugin-development><custom-fieldtype>
How do I update the content of a field type in the onAfterElementSave() method?
# How do I update the content of a field type in the onAfterElementSave() method?

(Asked by: username_0 on 2014-08-13)

I am building a field type for Craft that needs to do additional processing to the saved data once the element id is available. For this reason, the `prepValueFromPost()` method won't work, since the element id isn't available yet.

So how to update the content of the current element from the `onAfterElementSave()` method?

**Tags:** plugin-development, custom-fieldtype


---

## 1 answers

### Answer by username_1 on 2014-08-13. Score: 4 | Accepted answer

This will return the content for the specific element instance you're on:
$this->element->getContent()

And from there you can do your additional content processing.
When you're ready so save it, you can call:
craft()->content->saveContent($this->element);

There are several examples in craft/app/fieldtypes folder where Craft's native field types do additional processing like this.

> **Comments:**
> **username_0**: So if I update a property on the `ContentModel`, how does that data get saved to the db? When I update my property, the new data isn't saved to the db and you can't call `save()` on models.  
> **username_0**: I figured it out. I just ran the following code to save the content. `craft()->content->saveContent($this->element);` If there is a better way, let me know. If not, may be helpful to update your answer with that code and I'll mark it as correct.  
> **username_1**: That's the way... updated!  

---

