2510 Posts in 675 Topics by 520 members
Data Model Questions
SilverStripe Forums » Data Model Questions » search form results , block image searching
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 1104 Views |
-
search form results , block image searching

19 February 2010 at 10:03am
Hi
I'm using standard search form function
function SearchForm() {
$searchText = isset($this->Query) ? $this->Query : '';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
);
$actions = new FieldSet(
new FormAction('results', 'find product')
);return new SearchForm($this, "SearchForm", $fields, $actions);
}
/**
* Process and render search results
*/
function results($data, $form){
if($form->getSearchQuery() == NULL) {
$data = array(
'Results' => '',
'Query' => '',
'Title' => 'Your results'
);
} else {
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Your results'
);
}return $this->customise($data)->renderWith(array('Results_Page', 'Page'));
}but it also searchs image files
if file has a name for example:kitchen_image_2.jpg
and i want to search "kitchen" , one of the results is this image
also if i have a folder "kitchen" with many images, they also are including to search resultso my question is
how to block image searching ? -
Re: search form results , block image searching

22 February 2010 at 8:44am
In your Page Controller you'll have a method called SearchForm(). The last line should read:
return new SearchForm($this, "SearchForm", $fields, $actions);
Change this to:
$form = new SearchForm($this, "SearchForm", $fields, $actions);
$form->classesToSearch(array('SiteTree'));
return $form; -
Re: search form results , block image searching

22 February 2010 at 10:47pm
maby you can help with with second problem
also with image in serach results : )i have product page with
has_one {
'Img' => 'Image'
}but standard search form only searching in the SiteTree so i cant display product image
how to modify this search form function to display images ? -
Re: search form results , block image searching

3 April 2011 at 8:50am
If you know that one form needs to search Files and Pages and the other searches JUST the pages and it's ALWAYS going to be like that, couldn't you hardcode a parameter in your template for your overloaded SearchForm() function?
| 1104 Views | ||
|
Page:
1
|
Go to Top |



