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

Extend the datawriter _preSave function instead of the controller

cclaerhout

Well-known member
#1
I'm not sure it can help, but here's a quick message for coders who have directly extended the datawriter (ie: _preSave) instead of the controller.

Don't do only this:
PHP:
    protected function _preSave()
    {
        $_input = new XenForo_Input($_REQUEST);
        $myNewField = $_input->filterSingle('my_new_field', XenForo_Input::UINT);
        $this->set('my_new_field', $myNewField);
      
        return parent::_preSave();
    }
Do this:
PHP:
    protected function _preSave()
    {
        $_input = new XenForo_Input($_REQUEST);
        $myNewField = $_input->filterSingle('my_new_field', XenForo_Input::UINT);
    
        if($_input->inRequest('my_new_field'))
        {
            $this->set('my_new_field', $myNewField);
        }
      
        return parent::_preSave();
    }
It will avoid your extented field to save a blank value when the controller of this datawritter is called from another location (see here or there) :coffee: