• 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...

#1
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:
You have some syntax problems, but that's the right idea.
You really need a programmer to write this for you.
So i posted it here. Any help would be very appreciated. Advice too but i'm not much of a programmer.
 

Onimua

Well-known member
#2
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;
    }