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

Data passed to custom userfield callbacks

Discussion in 'XenForo Development Discussions' started by Jake Hakoda Shirley, Jun 9, 2012.

  1. Jake Hakoda Shirley

    Jake Hakoda Shirley Active Member

    Hey guys, I am currently trying to make it so our users cannot enter the same in-game name as another user on the forum. To my knowledge, the custom userfield callback method only supports three variables, those being 'array $field, &$value, &$error'. Is there any way I could grab the user's info (who is submitting the name)?
    grundyboy34 likes this.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This PHP code will give you access to the user record of the currently logged in user:

    		$visitor = XenForo_Visitor::getInstance();
    		if ($visitor['user_id'] == ...)
  3. ragtek

    ragtek Guest

    BUT attention:
    Admins (with user edit permissions) can edit everybody in the acp.

    So if they edit a userfield, $visitor won't be the user with the field, it will be the admin who's changing the value;)
  4. x3sphere

    x3sphere Active Member

    Interesting, I wasn't aware the custom field callbacks execute in the admin CP. Anyway, for handling verification / extra processing on our custom fields I extended the actionPersonalDetailsSave function, and that doesn't get executed on the admin CP.
  5. ragtek

    ragtek Guest

    the custom field callback is a validator which is run everywhere where the custom fields are set via the user datawriter

    $valid $fieldModel->verifyUserFieldValue($field$value$error);
    if (!
    if (!
    $this->getOption(self::OPTION_ADMIN_EDIT) && $field['required'] && ($value === '' || $value === array()))
    $this->error(new XenForo_Phrase('please_enter_value_for_all_required_fields'), "custom_field_$fieldId");
  6. ragtek

    ragtek Guest

Share This Page