Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions /

Search form as generated by SS


Reply


7 Posts   2711 Views

Avatar
PeteF

Community Member, 8 Posts

8 May 2009 at 2:25am

Hi guys

I'm using the standard Searchform function within a theme in order to provide a site search facility.
1: I'm just wondering where the CSS for this form is pulled in from?
2: Also where is the PHP file that builds this form? Basically I want to restructure the way it builds the form so that it only uses one div instead of putting the input field and the button in two separate divs.

Cheers
Pete

Avatar
Nivanka

Community Member, 398 Posts

8 May 2009 at 3:32am

There is no such specific php file which perform search on SilverStripe.
it is the following method which is in your Page class (/mysite/Page.php)

/**
    * Process and render search results
    */
   function results($data, $form){
       $data = array(
       'Results' => $form->getResults(),
       'Query' => $form->getSearchQuery(),
       'Title' => 'Search Results'
       );

       return $this->customise($data)->renderWith(array('Page_results', 'Page'));
   }

and to change the look and feel of the results you will have to edit the Page_results.ss which you can find in your theme folder.

Also it uses the standard css file, which are layout.css, typography.css and the form.css, but you can add a new CSS you wish there by calling the Requirements::css method in the method which I mentioned above.

Avatar
vstrazz

Community Member, 63 Posts

8 May 2009 at 6:16am

I think he is wanting to change the way the form itself is generated Nivanka.

I would suggest manipulating the final output with css, because changing the way forms are created in silverstripe would be a pretty complex thing to do; and in the end could leave you with broken forms else where.

You can also actually make the html for the form yourself in the template instead of calling the function.

for instance if you call $SearchForm you could do this

<form id="SearchForm_SearchForm" enctype="application/x-www-form-urlencoded" method="get" action="/home/results">
<fieldset>
<input id="SearchForm_SearchForm_formController" class="hidden" type="hidden" value="home/" name="formController">
<input id="SearchForm_SearchForm_executeForm" class="hidden" type="hidden" value="SearchForm" name="executeForm">
<div class="inp-text-holder">
<input id="SearchForm_SearchForm_Search srch" class="txt" name="Search" type="text" value="Site Search">
</div>
<input id="SearchForm_SearchForm_action_searchresults m_search_sub" class="button_go" type="image" src="$ThemeDir/images/btn-search.png" name="action_searchresults" value="" >
</fieldset>
</form>

and it would work perfectly fine.

Avatar
PeteF

Community Member, 8 Posts

8 May 2009 at 10:38pm

Thank you very much guys, that's fantastic, just what I was looking for.
I could'nt find the references to the css classes in the files you mentioned Nivanka, but I will look again.
The info regarding manually creating the form in HTML - that's what I'll do for now to get my demo site up and running! :)

Thanks so much guys, you've been a real help.

Kind regards

Pete

Avatar
robcub

Community Member, 14 Posts

11 May 2009 at 2:17am

I am having a lot of difficulty styling the site search in SilverStripe.

I have pasted in the HTML recommended by vstrazz which has been really helpful although I'm still unable to either get the input button on the same line as the search field.

http://www.mylocalmates.com

Avatar
Nivanka

Community Member, 398 Posts

11 May 2009 at 2:56am

Edited: 11/05/2009 2:57am

note that both the inputs are in divisions, so either you will have to float them, or will have to get them out of the divisions.

Avatar
robcub

Community Member, 14 Posts

11 May 2009 at 11:03am

Thanks, Nivanka, I'll struggling with it but I'll get there.