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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

Understanding the SearchForm Method


Go to End


6 Posts   2704 Views

Avatar
J2-Paul

Community Member, 51 Posts

18 June 2010 at 12:13pm

Edited: 18/06/2010 12:15pm

Can someone please explain how to extend the SearchForm class.

My aim is to modify the default text and button text initially, but will probably extend to more changes later.

I have located the function in this file " \saphire\search\ContentControllerExtension.php"

The easy thing to do would be to make the changes in this file. But messing with the core files is not ideal of course.

I have tried extending the Searchform.php class as follows:

Create new class "SiteSearch.php" in mycode

class SiteSearch extends SearchForm {

		function __construct($controller,$name){

			parent::__construct($controller,$name);
	
	}

}

Putting $SiteSearch in my template and I get the default form rendering OK. But I get the error below.

Any help would be much appreciated.

[User Error] Uncaught Exception: Object->__call(): the method 'getviewer' does not exist on 'DataObjectSet'
GET /home/SiteSearch?Search=&action_getResults=Go

Line 724 in E:\websites\IRIS\v2\sapphire\core\Object.php
Source

715 				
716 				default :
717 					throw new Exception (
718 						"Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true)
719 					);
720 			}
721 		} else {
722 			// Please do not change the exception code number below.
723 			
724 			throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);
725 		}
726 	}
727 	
728 	// -----------------------------------------------------------------------------------------------------------------
729 	
730 	/**

Trace

    * Object->__call(getViewer,Array)
    * DataObjectSet->getViewer(SiteSearch)
      Line 155 of Controller.php
    * Controller->handleRequest(SS_HTTPRequest)
      Line 199 of ContentController.php
    * ContentController->handleRequest(SS_HTTPRequest)
      Line 67 of ModelAsController.php
    * ModelAsController->handleRequest(SS_HTTPRequest)
      Line 283 of Director.php
    * Director::handleRequest(SS_HTTPRequest,Session)
      Line 127 of Director.php
    * Director::direct(home/SiteSearch)
      Line 127 of main.php


Avatar
Willr

Forum Moderator, 5523 Posts

18 June 2010 at 3:47pm

If you want to override the search form (well the button and the text copy the content from the ContentControlellerExtension class to your Page.php then you can customize it as much as you wish.

Avatar
J2-Paul

Community Member, 51 Posts

18 June 2010 at 7:33pm

Thanks Willr. I think the penny has dropped here! I am kicking myself right now!

Much appreciated!

Avatar
BlueO

Community Member, 52 Posts

9 July 2010 at 7:36pm

Thank you for posting this! There are a lot of conflicting posts and this one finally answers how to customise the search form and button in 2.4

b

Avatar
Pinky

Community Member, 2 Posts

3 August 2010 at 7:25pm

It is too good

Avatar
Pinky

Community Member, 2 Posts

3 August 2010 at 7:26pm

It is too good