Hi all
I’m using MODx 0.9.6 and I’m having a problem with a search snippet I’ve created, it’s a bit similar to the AjaxSearch-snippet, except I’m using it to search a database of news articles. Anyways, the problem is with the form submit POST method (I think).
What happens is the following:
1. I type in some text in the textfield (example "this is some text"), and then I press submit. I can then get the value with $_POST[’textfield’]
2. BUT, when I try to repeat the process with another text-value ("this is some more text") and press the submit button, all I get is the old value from (1). It doesn’t help how many times I try with different values or refresh.
3. What is strange is that if I go into the MODx manager, opens the snippet, save it, and then tries to type in a new value I will get the correct one. But only the first time.
4. It seems like the old POST value remains in memory or something. BTW, I have the same problem with the AjaxSearch snippet (which worked fine in MODx 0.9.5).
Hope you understood all that, any help will be greatly appreciated.
Thanks.
The snippet code:
require_once("assets/snippets/SiteSearch/SiteSearch.class.php"); //just the class that handles the search itself
$siteSearchObj = new SiteSearch(); //a new search object
$targetPage = 0; //where the search result is to be shown, default: current page
$showSearchForm = 1; //if the search-form is to be show, default: true
$showSearchResult = 1;
$string = null; //search string
if(isset($target))
$targetPage = $target;
if(isset($showForm))
$showSearchForm = $showForm;
if(isset($showResult))
$showSearchResult = $showResult;
if($showSearchForm == 1)
include("assets/snippets/SiteSearch/form.template.php");
if($showSearchResult == 1) {
if(isset($_POST[’btnSiteSearch’])) {
if(isset($_POST[’txtSiteSearch’])) {
$string = $_POST[’txtSiteSearch’];
$siteSearchObj->doSearch($string);
}
}
}
The form:
<form id="siteSearchForm" action="<?php echo ’index.php?id=’.$targetPage ?>" method="post" enctype="application/x-www-form-urlencoded">
<fieldset>
<input id="siteSearchInput" type="text" name="txtSiteSearch" value="" maxlength="100" />
<input id="siteSearchButton" type="submit" name="btnSiteSearch" value="Søk" />
</fieldset>
</form>
-
MODX Staff
- 10,725 Posts
Your page must either not be cacheable or you must ensure that you are calling your snippet with non-cacheable tags, e.g. [!NonCacheableSnippet!], rather than [[CacheableSnippet]].