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

possible to autocomplete usernames in external site?

Discussion in 'XenForo Development Discussions' started by tresdollares, Feb 15, 2016.

  1. tresdollares

    tresdollares New Member

    I am not sure if this is the correct forum to post in, but I am looking for a way to integrate Xenforo's ability to autocomplete member names (such as when starting a conversation with someone) to my external site. I don't know if this is possible, or how much work it will take. But Basically, I need to be able to allow users to type in a field (in my external site) and have the usernames show up (attempt to autocomplete).


    One of the things my site needs is the ability to "tag" other members, and I think this is the first step in being able to make that work. Would be great if someone could point me to the right direction, or let me know if this can be done.

    I am already able to get information about the current logged in user by making use of info I found here: https://xenforo.com/community/threads/using-xenforo-permission-outside-of-xenforo.7585/ ..now I just need to be able to add that other feature.
  2. Thomas.B

    Thomas.B Well-Known Member

    I think that should be possible.

    You would need to include the xenforo.js which contains the autocomplete function (XenForo.AutoComplete). To activate the autocomplete feature, add the AutoComplete class to the corresponding input element. By default XenForo.AutoComplete uses the following URL for the AJAX search requests: index.php?members/find&_xfResponseType=json. You can change this URL by adding a „acurl“ data attribute to the input element. For example: data-acurl="http://mysite.com/xenforo/index.php?members/find&_xfResponseType=json

    Also in order to actually get an AJAX response you would need to first assign a valid token to XenForo._csrfToken. You can get a token from a visitor instance with XenForo_Visitor::getInstance()->csrf_token_page.
    Robust and tresdollares like this.
  3. tresdollares

    tresdollares New Member

    Thank you for this. I will try to implement this later this week.
    Regarding the CSRF token, what is the difference between these two and when should one use the other?
    (I haven't done any thorough research yet so pardon me if that question sounds dumb).

    $visitor XenForo_Visitor::getInstance();

    // this
    $token $visitor->csrf_token_page

    // or this?
    $token $visitor->get('csrf_token');
  4. Thomas.B

    Thomas.B Well-Known Member

    Well, in your example code there are actually two differences: (1) the token types and (2) how the tokens are obtained. Regarding the former: A token is associated with a particular (registered) user and doesn't change. This „user token“ is used by XF to generate a „page token“ for each page request. And for certain requests you will have to provide a valid page token.

    The other difference is just that in the second statement, the token is accessed via an overloaded object property which is actually just a shortcut for the get() method.
    tresdollares likes this.

Share This Page