We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    I’m integrating an existing search script (which works correctly) into Modx as a snippet but the script is having problems getting past retrieving the search url variable.

    My test page is in the directory test/search.

    Modx has friendly urls turned on.

    The page has a simple search form at the top of the page:

    <form name="form" action="[~[*id*]~]" method="get">
     <input type="text" name="q" />
     <input type="submit" value="Search" /> 
    </form>



    ...followed by the search snippet:

    $var = isset($_GET['q']) ? mysql_real_escape_string($_GET['q']) : '';
    $search = trim($var); //trim whitespace
    echo $search;
    deleted remaining code



    On first loading the page, http://www.site.com/test/search, $search value displays as "test/search" instead of nothing.

    When I enter a search term and submit a 404 page appears instead of displaying the search term, eg url:

    http://www.site.com/test/search?q=sydney

    Stumped. No doubt it’s probably something simple I’ve overlooked!
      Mostly harmless.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      "q" is already used by MODx for its friendly URLs; the rewrite engine converts domain.com/alias.html to index.php?q=alias. Using a different name for your variable may fix the problem.

      Also consider that when friendly URLs are being used, your query string has to start with ?, but if not it has to use & since the index.php?id=xx is already using the ?

      Is there any reason why the search form can’t use "post" instead of "get"?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org