We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27716
    • 126 Posts
    This is an attempt to pass the search string to a URL after searching.

    The site is http://www.nepal.tv

    The code Im using is below.

    [+as.showForm:is=`1`:then=`
    <form [+as.formId+] action="[+as.formAction+]?AS_search?=[+as.searchString+]" method="post">
        <fieldset style="border:none; width:0px; padding:0px; margin:0px;">
        <input type="hidden" name="advSearch" value="[+as.advSearch+]" />
        <label for="ajaxSearch_input">
          <input id="ajaxSearch_input" class="search-form" type="text" name="search" value="[+as.searchString+]"[+as.inputOptions+] />
        </label>
        <label for="ajaxSearch_submit">
          <input id="ajaxSearch_submit" type="submit" name="sub" value="[+as.submitText+]" class="yt-button yt-button-primary" />
        </label>
        </fieldset>
    </form>
    `+]
    [+as.showIntro:is=`1`:then=`
    <p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
    `+]
    [+as.showResults:is=`1`:then=`
    [+as.results+]
    `+]


    Ive tried this with value="[+as.searchString+]" and without [+as.searchString+] in the value.

    The problem is.

    With this code
    <form [+as.formId+] action="[+as.formAction+]?AS_search?=[+as.searchString+]" method="post">


    It will pass the string the SECOND time you search. So if you search the first time it will NOT pass the string. But then hit search the second time off the results page it WILL pass the string.

    Any suggestions on how i can get it to pass the string on the first search?



      • 5811
      • 1,717 Posts
      What are you trying to do ?
      Usually, you set a first snippet call on a page or on a template and then you display the results on a landing page. And the searchString is passed thru a $_POST variable.
        • 27716
        • 126 Posts
        I am trying to get the variable to display in the URL as happens when you search the Second time.

        I want it to happen the first time you search.

        The purpose is that Google analytics picks up this string from the URL in site search tracking.
          • 5811
          • 1,717 Posts
          As I understand Google analytics require an url with something like &s=mysearchterm
          This implied to have to use a form witth a get method. This is not the method supported by AS.

          If you would like hack the code to modify this behavoiur try to do as follow. With AS1.8.4 code, replace "AS_search" by "search" in the lines:
          assets\snippets\ajaxSearch\classes\ajaxSearch.class.inc.php
          	Line 375:     if ( isset($_POST['search']) || isset($_GET['AS_search']) || isset($_GET['FSF_search'])) {
          	Line 380:       } elseif (isset($_GET['AS_search'])) {
          	Line 381:         $this->searchString = urldecode($_GET['AS_search']);
          	Line 551:           if (!isset($this->subSearch)) $varLink['pagingLink'] = $modx->makeUrl($modx->documentIdentifier,'','AS_offset='.$nrp.'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch));
          	Line 552:           else $varLink['pagingLink'] = $modx->makeUrl($modx->documentIdentifier,'','AS_offset='.$nrp.'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch).'&subsearch='.urlencode($this->subSearch));
          And then in
          assets\snippets\ajaxSearch184\classes\ajaxSearchPopup.class.inc.php
          	Line 401:         $this->varResults['moreLink'] = 'index.php?id='.$this->cfg['moreResultsPage'].'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch).'&subsearch='.urlencode($this->cfg['subSearch']);
          	Line 403:         $this->varResults['moreLink'] = 'index.php?id='.$this->cfg['moreResultsPage'].'&AS_search='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch);
          
          and in the original layout template, replace method="post" by method="get":
          <form [+as.formId+] action="[+as.formAction+]" method="get">


          I haven’ tested this hack and analysed the impacts and I don’t support this solution (for the moment), but let me know the results

          I am also interested to know if used AS with google analytics is a feature request for lot of people
            • 27716
            • 126 Posts
            Hi Coroico,

            The code below in the template works fine, Analytics tracks in. This is in the template file.
            <form [+as.formId+] action="[+as.formAction+]?AS_search?=[+as.searchString+]" method="post">


            BUT...

            The problem is the first time you search it doesnt work. But if you search, then search again it does work.

            You can see example at http://www.nepal.tv

            Would love someone to take a look at that solution and fix, as it is a very simple minor hack.