• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

_preSave() and _postSave() explained?

Could someone please, help me understand those two methods?
    * Post-save handling.
    protected function _postSave()
    * Pre-save handling.
    protected function _preSave()
Those are not very clear to me.

In my project, I am extending XenForo_DataWriter_User and my understanding is that I need to use those two methods to save the user data to the database.

Is there example code that I missed?

Liam W

Well-known member
_preSave is called before saving. You should set any new fields in that method, before calling parent.

_postSave is called after saving. Perform any post save actions etc.


Jake B.

Well-known member
_preSave runs before the data is actually saved, and _postSave is run after the data is saved. _preSave could be used to validate things, _postSave could be used to alter something in another table if necessary after the data has been saved (such as updating the last post date on a thread when a new post is made)
I am still not understanding how I am supposed to same my data

I created a new page: /index.php?account/email-preferences with a checkbox that I would like to save the state of in the DB.
class SilverpopIntegration_XenForo_DataWriter_User extends XFCP_SilverpopIntegration_XenForo_DataWriter_User {}
<form method="post" class="xenForm formOverlay NoFixedOverlay AutoValidator"
    action="{xen:link 'account/email-preferences-save'}"
    data-fieldValidatorUrl="{xen:link 'account/validate-field.json'}"
I must be missing something...


Well-known member
There is then: _postSaveAfterTransaction() which occurs after the transaction finishes. You should use this for stuff like Alerts and other notifications.