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

Using the search form from outside Xenforo Instance

Discussion in 'XenForo Development Discussions' started by Adam K M, Jul 8, 2014.

  1. Adam K M

    Adam K M Active Member


    I was just wondering how I would go about using the search form of Xenforo outside of the forum instance. Yesterday we were working on our homepage (located on the root domain, instead of forums.domain) and managed to style everything as needed - and the search form was working then.

    However, now, when I try to search for something from this external homepage, I get a
    ShortCut Central - Error
    Security error occurred. Please press back, refresh the page, and try again.
    I was wondering how to fix this, so that the search works again on my external homepage?

    Many thanks! :)
  2. JulianD

    JulianD Well-Known Member

    If you look closely to the hidden fields in the form, there's one called "xfToken". You need to specify the correct token in order to make it work.
    Adam K M likes this.
  3. Adam K M

    Adam K M Active Member

    Brilliant! I see it!

    The only question (or two) is... how do I fetch the correct token via php? I'm assuming that this token is regenerated every X days/hours, and manually re-adding it would be redundant. (And not to mention that there doesn't seem to be a lot of 'documentation' that I could find on this matter)
  4. JulianD

    JulianD Well-Known Member

    I'm not very used to the system in charge of generating the tokens but I'm pretty sure each visitor has a unique token of their own. You would need to instantiate the XenForo classes in your PHP script in order to generate a valid token. I'm only guessing though. Sorry I couldn't be of more help.
    Adam K M likes this.
  5. Aayush

    Aayush Well-Known Member

    You've got two ways to tackle this
    Code an API which boots up XF and uses XF native functions to search the DB and return the result in Json format.

    Curl the login page, do a regex search to grab the XF token value and then use that token to search via curl again.

    I have used both of them in some of my projects and I can assure you that both of them work. It's upto you to decide which one you want to use.

Share This Page