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

Other Need help with a query...

Discussion in 'Custom Service/Development Requests' started by Alofoxx, Jan 2, 2013.

  1. Alofoxx

    Alofoxx Member

    Im trying to make a php callback class::method for verifying 'field value' is the name of a registered user, like what the participants field uses when you start a new conversation.

    So far I have
    Code:
    <?php
    class Callback_UserField
    {
        public static function validate($field, &$value, &$error)
      {
        if (userCheck($value))
          {
            return true;
          }
          else
          {
            $error = 'The player must be registered on our website.';
            return false;
          }
        }
     
     
     
      private static function userCheck ($userIn)
      {
        $db = XenForo_Application::get('db');
     
            $db->query("
              SELECT username FROM xf_user
              WHERE username = '%s'
              mysql_real_escape_string($userIn),
           
              $result = mysql_query($query);
           
        if (!$result)
        {
          return false
     
          else
          {
            if ($result == $userIn)
            {
              return true;
            }
            else
            {
              return false;
            }
          }
        }
      }
    }
    
    Jake said:
    So i posted it here. Any help would be very appreciated. Advice too but i'm not much of a programmer.
     
  2. Onimua

    Onimua Well-Known Member

    Try this:
    PHP:
        public static function validate($field, &$value, &$error)
        {
            
    $userModel XenForo_Model::create('XenForo_Model_User');
     
            if (!
    $userModel->getUserByName($value))
            {
                
    $error 'The player must be registered on our website.';
                return 
    false;
            }
     
            return 
    true;
        }
     
    Chris D likes this.

Share This Page