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

UserField callback

Discussion in 'XenForo Development Discussions' started by blackvoid, Nov 24, 2011.

  1. blackvoid

    blackvoid Active Member

    How should the userfield callback function look. Ive found out that the class should extend XenForo_Model_UserField, but since I haven't a documentation for XenForo which shows which function I should extend and function variables

    Currently the class looks like this.

    PHP:
    <?php
     
    class DynamicEffect_Minecraft extends XenForo_Model_UserField
        
    static public function verifyAccountName(&$accountName, &$error)
        {
            
    $url 'http://www.minecraft.net/haspaid.jsp?user='.$accountName;
            
    $contents trim(file_get_contents($url));
            if(
    $contents == 'false')
            {
                
    $error = new XenForo_Phrase('no_paid_minecraft_account');
                return 
    true;
            }    else    {
                return 
    true;
            }
        }
    }
     
  2. ragtek

    ragtek Guest

    no, the callback function is ONLY for validating and doesn't have to extend userfield model.

    if you check the code
    PHP:
    case 'callback':
                                
    $matched call_user_func_array(
                                    array(
    $field['match_callback_class'], $field['match_callback_method']),
                                    array(
    $field, &$value, &$error)
                                );
    you'll see that you need 3 params => field, value and if necessary => the error reference
     
  3. blackvoid

    blackvoid Active Member

    Thank you, got it working.
     
  4. silence

    silence Well-Known Member

    Bumping with the code that works successfully incase someone wants it! :p
    PHP:
    <?php
     
    class CustomCallback_ProfileField_MineCraft
    {
        public static function 
    verifyAccountName($field, &$accountName, &$error)
        {
            
    $url 'https://www.minecraft.net/haspaid.jsp?user=' $accountName;
            
    $contents trim(file_get_contents($url));
     
            if(
    $contents == 'false')
            {
                
    $error "You cannot link a Minecraft account that hasn't purchased the game!";
                return 
    false;
            }
            else
            {
                return 
    true;
            }
        }
    }
     
    Jake Bunce likes this.
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

Share This Page