Is it possible to return custom error messages on option validation callback ?

#1
I followed this tutorial but I get the below error when the callback returns false.

Code:
Server Error
Parameter 2 to Callback_UserField::validate() expected to be a reference, value given

[LIST=1]
[*]XenForo_Application::handlePhpError()
[*]call_user_func_array() in XenForo/DataWriter/Option.php at line 346
[*]XenForo_DataWriter_Option->_validateOptionValuePreSave() in XenForo/DataWriter/Option.php at line 211
[*]XenForo_DataWriter_Option->_preSave() in XenForo/DataWriter.php at line 1446
[*]XenForo_DataWriter->preSave() in XenForo/DataWriter.php at line 1385
[*]XenForo_DataWriter->save() in XenForo/Model/Option.php at line 572
[*]XenForo_Model_Option->updateOptions() in XenForo/ControllerAdmin/Option.php at line 174
[*]XenForo_ControllerAdmin_Option->actionSave() in XenForo/FrontController.php at line 347
[*]XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
[*]XenForo_FrontController->run() in /Users/tomchristian/Dropbox/www/xenforo1.3/admin.php at line 13
Any ideas?
 

Brogan

XenForo moderator
Staff member
#2
Yes, it's possible, I do it for my add-on.

Here's a snippet.

PHP:
    public static function verifyOption(&$optionValue, XenForo_DataWriter $dw, $fieldName)
    {
        if ($dw->isInsert())
        {
            return true;
        }

        if (!$optionValue)
        {
            $optionValue = $dw->get('default_value');

            return true;
        }

        if ($optionValue['featurer'] == 'member')
        {
            $existingUser = XenForo_Model::create('XenForo_Model_User')->getUserByName($optionValue['name']);

            if (!isset($optionValue['forums']) && !$existingUser)
            {
                $dw->error(new XenForo_Phrase('cta_ft_option_select_at_least_one_forum_enter_valid_member_name'), $fieldName);
                return false;
            }
 
Top