5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 432 Views |
-
How to extend SearchForm in SS v.3

21 September 2012 at 1:28am Last edited: 21 September 2012 2:06am
I use SilverStripe 3.x. and I need to make some changes in SearchForm class - e.g. modify search results page length.
How can I do it?The following code in mysite/code/MySearchForm.php file
unfortunately doesn't work
class MySearchForm extends SearchForm {
protected $pageLength = 100;
}Thanks!
-
Re: How to extend SearchForm in SS v.3

22 September 2012 at 4:49pm Last edited: 22 September 2012 4:50pm
You can override the default search form by copying the form from ContentControllerSearchExtension to your Page class then alter it as you need.
class Page_Controller extends ContentController {
public function SearchForm() {
$searchText = _t('SearchForm.SEARCH', 'Search');if($this->owner->request && $this->owner->request->getVar('Search')) {
$searchText = $this->owner->request->getVar('Search');
}$fields = new FieldList(
new TextField('Search', false, $searchText)
);
$actions = new FieldList(
new FormAction('results', _t('SearchForm.GO', 'Go'))
);
$form = new SearchForm($this->owner, 'SearchForm', $fields, $actions);
$form->classesToSearch(FulltextSearchable::get_searchable_classes());
$form->setPageLength(1000);return $form;
}
}
| 432 Views | ||
|
Page:
1
|
Go to Top |


