Search box in website
Permalink 3 users found helpfulHow can I enable a site-wide search box on my website? Just like here we have a search box to search the forums...
Now, I place this code in my theme template (usually in the elements/header.php file, but may be different for you depending on the theme you're using):
<form method="get" action="<?php echo $this->url('/search') ?>"> <input type="text" name="query" /> <input type="submit" value="Search" /> </form>
Those are the bare minimum of things you need in the search form in order for it to work, but if you want to style it via CSS you will need to add classes to the input fields (to differentiate between the text and submit fields), and probably a class or id on the form itself. Often I'll use an image button for the submit instead of the submit element, which is fine -- the important thing is that the textbox is named "query" and that the form method is "get" and the form action goes to the "search results" page you set up above.
Hope that helps!
-Jordan
<div class="content"> <?php if( !empty($_REQUEST['query']) || isset($_REQUEST['akID'])) { $q = $_REQUEST['query']; $_q = preg_replace('/[^A-ZÄÜÖa-zäöüß\']/i', '', $_REQUEST['query']); Loader::library('database_indexed_search'); $ipl = new IndexedPageList(); $aksearch = false; if (is_array($_REQUEST['akID'])) { Loader::model('attribute/categories/collection'); foreach($_REQUEST['akID'] as $akID => $req) { $fak = CollectionAttributeKey::getByID($akID); if (is_object($fak)) { $type = $fak->getAttributeType(); $cnt = $type->getController();
It's the first time i have a problem with the search block.
I've already tried to set up a custom area for search in the /jobs/index_search.php, update the settings in Dashboard > Sitemap > Page Search > Setup Index and running manually the Index Search Engine job.
Any suggestions?
Thanks!
in the controller.php of the search block, $aksearch is always NULL, so far, but the last part in this code, always evaluates to false. This because I selected the option "post results to another page" and the variable
... || $this->resultsURL != ''
forces the function to return false.
if (is_array($_REQUEST['akID'])) { Loader::model('attribute/categories/collection'); foreach($_REQUEST['akID'] as $akID => $req) { $fak = CollectionAttributeKey::getByID($akID); if (is_object($fak)) { $type = $fak->getAttributeType(); $cnt = $type->getController(); $cnt->setAttributeKey($fak); $cnt->searchForm($ipl); $aksearch = true; } } } // STRANGE CONDITION /*
Anyway, i temporary commented those lines until i figure out what to do with them. Got my search working now
If someone could explain me what's the logic on that piece of code i'll be very thankful
To have a persistent search block on all pages, you can do this a couple different ways. Without hard coding, you can save a Search block to your scrapbook, then copy that saved block to your Page defaults.
Hard coding is a more difficult approach if you don't understand PHP.