Using the search form from outside Xenforo Instance

Adam K M

Active member
Hello,

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! :)
 
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.
 
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.
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)
 
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)
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.
 
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.

or
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.
 
Back
Top Bottom