Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Search form as generated by SS

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2583 Views
  • PeteF
    Avatar
    Community Member
    8 Posts

    Search form as generated by SS Link to this post

    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

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Search form as generated by SS Link to this post

    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.

  • vstrazz
    Avatar
    Community Member
    63 Posts

    Re: Search form as generated by SS Link to this post

    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.

  • PeteF
    Avatar
    Community Member
    8 Posts

    Re: Search form as generated by SS Link to this post

    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

  • robcub
    Avatar
    Community Member
    14 Posts

    Re: Search form as generated by SS Link to this post

    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

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: Search form as generated by SS Link to this post

    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.

  • robcub
    Avatar
    Community Member
    14 Posts

    Re: Search form as generated by SS Link to this post

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

    2583 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.