Jump to:

5102 Posts in 1520 Topics by 1116 members

Customising the CMS

SilverStripe Forums » Customising the CMS » How to extend SearchForm in SS v.3

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 432 Views
  • pga
    Avatar
    Community Member
    8 Posts

    How to extend SearchForm in SS v.3 Link to this post

    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!

  • Willr
    Avatar
    Forum Moderator
    5171 Posts

    Re: How to extend SearchForm in SS v.3 Link to this post

    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

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.