Needing to add a form and submit button within a thread view


Well-known member
I have an ad that displays after the first post on every thread on my forum, and it is constructed to look like a user post to keep the flow and not be too much of an eyesore. I am trying to add a small search form to that particular 'fake' post, that redirects the user to an external site if they choose to submit it.

The search form works on my forum home without any issues at all, but if I try to submit the form from inside the thread, I get an error of "Security error occurred. Please press back, refresh the page, and try again."

The form is built simply by calling on an external javascript file on another domain, so I don't have any customization options when it comes to how it creates the form. Is there anything I can wrap it in within the template file so xenforo doesn't get mad at an external form being submitted from within a post? Or is the issue something else entirely?


woops, thought I was in the customization forums. Move if needed :/


XenForo moderator
Staff member
A security error is usually related to a stale/expired token. Are you hard coding a token value in the template?


Well-known member
No, nothing like that. The most complex thing in the template that I thought xenforo would care about is:

<xen:if is="{$post.position} == 0  AND !{$message.conversation_id}">
The rest is pretty simple html and some javascript.

It tries to send me to /inline-mod/post/switch when the form is submitted. This happens regardless if you are logged in or not.

I guess I can show a link instead of just talking about it. I hate having broken things on my forum, so I had taken it off.

After the first post is where you can see the form, under the banner ad spot. If you have adblock then you probably won't see anything.


XenForo moderator
Staff member
Without looking at it, at a guess I would say it's the .js causing the problem if it's redirecting you to that URL.


Well-known member
I tried another ad_ template location and it works, so it is something specifically with the ad_message_below template that is causing the problem. Maybe I'll be able to work around it.


XenForo moderator
Staff member
Clearly there's a .js conflict between your added code and the inline moderator functions js.

Where did you add the .js? In which template?


Well-known member
The ad_message_below template is what I am using at the moment. The remote .js file is as follows:

(function() {
    var skimlinks_search_id_in = window.skimlinks_search_id_in || false;
    function skimlinksGetID() {
        var skim_id_in = window.skimlinks_search_id_in || false;
        if (skim_id_in && skim_id_in.indexOf('1X1') != -1){ skim_id_in = false; }
        if (!skim_id_in){
            var skim_id_in = window.skimlinks_search_id || false;
        if (!skim_id_in){
            var    skim_id_in = window.skimlinks_pub_id || false;
        if (!skim_id_in){
            var skimlinks_tags = document.getElementsByTagName('script');
            var skimlinks_url = new RegExp("http://g\.skim*");
            for(var skimlinks_i = 0; skimlinks_i < skimlinks_tags.length; ++skimlinks_i) {
                var skimlinks_src = "";
                if(skimlinks_tags[skimlinks_i] !== undefined){
                    skimlinks_src = skimlinks_tags[skimlinks_i].src;
                    if(skimlinks_url.test( skimlinks_src ) === true) {
                        var skimlinks_pos_search_id_in = skimlinks_src.slice((skimlinks_src.lastIndexOf('/') + 1), skimlinks_src.indexOf('.', skimlinks_src.lastIndexOf('/') +    1));
                        if (skimlinks_pos_search_id_in.indexOf('amazon') != -1 || skimlinks_pos_search_id_in.indexOf('ebay') != -1){ skim_id_in = false; } else { skim_id_in = skimlinks_pos_search_id_in;}
                        skimlinks_i = skimlinks_tags.length;
        if (!skim_id_in){
            var    skim_id_in = '1X1';
        window.skimlinks_search_id_in = skim_id_in;
        var cl = 'skimlinkspubid';
        var elem = document.getElementsByTagName('input');
        var elsLen = elem.length;
            for (var i = 0; i < elsLen; i++) {
                if (elem[i].className == cl) elem[i].value = skim_id_in;
    skimlinks_search_id_in = window.skimlinks_search_id_in; 
    var uniq_id = '',
            sendurl = '',
            imgurl = '',
            class_name = 'amazon';
    for (var i = 0; i < 16; i++) {
        uniq_id += Math.floor(Math.random() * 10);
    document.write("<form method='GET' class='" + class_name + "' id='skimlinks_phrase_search' onsubmit='skimlinksGetID(); return true;' target='_blank' action='' style=\"display: inline;\">");
    document.write("<input class='skimlinks_phrase_query' id='skimlinks_phrase_query_" + uniq_id + "'  name='field-keywords' style=\"padding: 2px; background:    #FFFFFF url('" + imgurl + "') left no-repeat;\" maxlength='100' type='text' value='' />");
    document.write("<input name='skimlinks_search_product' value='amazon'  type='hidden' />");
    document.write("<input id='skimlinks_phrase_submit' value='Search' type='submit' />  <input name='url'    value='search-alias%3Daps' type='hidden' /> <input name='skimlinksurl' value='" + sendurl + "' type='hidden' /><input id='skimlinkspubid' class='skimlinkspubid' name='skimlinkspubid' value='"+skimlinks_search_id_in+"' type='hidden' /></form>");
    var skimlinks_amazon_text = document.getElementById('skimlinks_phrase_query_' + uniq_id);     
    skimlinks_amazon_text.value = '';
    skimlinks_amazon_text.onfocus = function() { = '#ffffff';
    skimlinks_amazon_text.onblur = function() {
        if (skimlinks_amazon_text.value === '') {
   = '#FFFFFF url("' + imgurl + '") left no-repeat';
    window.skimlinksGetID = skimlinksGetID;


XenForo moderator
Staff member
Try adding the .js to a template and including it in either the PAGE_CONTAINER, page_container_js_head or page_container_js_bodytemplate.

Then add your HTML to the ad template.


Well-known member
The problem with that is the .js file inserts the form wherever it is added to the page. I've seen a viglink person posting on here before, maybe I can find a skimlinks member as well and see if they can work out something that takes into account xenforo's javascript usage.


Active member
I'm having this exact same problem. I'm trying to put a search form in a conditional in the ad_message_below template and I'm getting the same error. Heres the code...

<xen:hook name="ad_message_below" />


<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND {$forum.node_id} != 12 AND {$forum.node_id} != 6 AND {$forum.node_id} != 4 AND {$forum.node_id} != 5 AND {$forum.node_id} != 39 AND {$forum.node_id} != 13 AND {$forum.node_id} != 36 AND {$forum.node_id} != 37 AND {$forum.node_id} != 14">
<center><form method="post" action="">
<table border="0" cellpadding="1" cellspacing="0" bgcolor="#ffffff"><TR><TD>
<table border="0" cellpadding="2" cellspacing="0" align="center" bgcolor="#FFFFFF">
<tr border="0">
<td valign="top" align="center" bgcolor="#ffffff">
<a href=""><img src="styles/uix/xenforo/mytopobanner.gif" width="100%"></a>
<td bgcolor="#FFFFFF" align="center" valign="middle"><font face="verdana,arial,helvetica" size="-2"><b>Search for&nbsp;</b></font>
<input type="text" name="feature" width=15 size=15 value="Place">
<font face="verdana,arial,helvetica" size="-1"> 
in <select name="state">
<option value="AL" selected>Alabama<option value="AZ">Arizona
<option value="AR">Arkansas<option value="CA">California
<option value="CO">Colorado<option value="CT">Connecticut
<option value="DE">Delaware<option value="DC">District of Columbia
<option value="FL">Florida<option value="GA">Georgia
<option value="ID">Idaho<option value="IL">Illinois
<option value="II">Indiana<option value="IA">Iowa
<option value="KS">Kansas<option value="KY">Kentucky
<option value="LA">Louisiana<option value="ME">Maine
<option value="MD">Maryland<option value="MA">Massachusetts
<option value="MI">Michigan<option value="MN">Minnesota
<option value="MS">Mississippi<option value="MO">Missouri
<option value="MT">Montana<option value="NE">Nebraska
<option value="NV">Nevada<option value="NH">New Hampshire
<option value="NJ">New Jersey<option value="NM">New Mexico
<option value="NY">New York<option value="NC">North Carolina
<option value="ND">North Dakota<option value="OH">Ohio
<option value="OK">Oklahoma<option value="OE">Oregon
<option value="PA">Pennsylvania<option value="RI">Rhode Island
<option value="SC">South Carolina<option value="SD">South Dakota
<option value="TN">Tennessee<option value="TX">Texas
<option value="UT">Utah<option value="VT">Vermont
<option value="VA">Virginia<option value="WA">Washington
<option value="WV">West Virginia<option value="WI">Wisconsin
<option value="WY">Wyoming</option>
<input type="submit" border=0 value="Go!" name="Search">


<xen:if is="{$forum.node_id} % {$xenOptions.messagesPerPage} == 6 AND !{$message.conversation_id}">