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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

CustomSearchForm snippet

Go to End

46 Posts   14247 Views


Community Member, 121 Posts

30 August 2010 at 9:09pm

awesome. best results I've had from any search situation so far with silverstripe. onbeforewrite and creating a master collection in metadescription was a great idea. Simple but something I didn't think about. I have it working with a few different dataobjects now and multiple page subclasses. Exactly what I wanted. Thanks again.


Community Member, 121 Posts

2 September 2010 at 6:44am

I have one other question which will hopefuly be relevant to other people as it seems a pretty common situation. What happens when the GlossaryTerm is connected to another dataobject through a hasmany or many_many connection? Supposing a GlossaryTerm could have many references, in searchcontext and modeladmin I could add into searchable fields 'MyReference.Title' but with setup it crashes the sql and I get an error such as

[User Error] Couldn't run query: ALTER TABLE "GlossaryTerm" DROP INDEX "SearchFields", ADD fulltext "SearchFields" (.....,....,....,...) Key column 'MyReferences' doesn't exist in table

Is there a fairly simple way to get around this? Thanks again


Community Member, 61 Posts

18 January 2011 at 8:35pm

I am getting a blank page when trying to use this search form.... All I want to do is search one type of DataObject. I have implemented the form in the Page.php. I tried using a simple control in the page template to display results.... is this the right way ?
<% if results %>
<% control results %>
<% end_control %>
<% end_if %>


Community Member, 121 Posts

15 June 2011 at 7:29am

Hi lanks

Sorry only just noticed your post. you still working on this by any chance?

If so it sounds like you are missing the template I don't see why I shouldn't work in though as long as nested correctly.

Heres the markup I have showing my results

<% if Results %>
<ul id="SearchResults">
<% control Results %>

<% if MenuTitle %>
<h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>

<% else %>
<h3><a class="searchResultHeader" href="$Link">$Title</a></h3>

<% end_if %>
<% if Content %>

<% end_if %>

<a class="readMoreLink" href="$Link" title="Read more about &quot;{$Title}&quot;">Read more about &quot;{$Title}&quot;...</a>


<% end_control %>
<% else %>
<%-- Example of a translatable string (see --%>
<% _t("", "Sorry, your search query did not return any results.") %>
<%-- By the way, template comments marked like this will be excluded from the HTML output --%>
<% end_if %>


Community Member, 95 Posts

5 July 2011 at 1:37am

Hello, Aram, a question for you:
what exactly changed with this custom search? I ask it cause none of the links work now, but search works fine.

To clerify, I had a LOTDPage where i displayer LOTDs - link of the day.
I made a few functions, one of them being a delete function, the other is a frontend edit function.
Both of them were controlled via link. Also, one of LOTDs was leading to my homepage.
In any case, non of the links works, even for my homepage, and every time i run dev/build it creates a new page called Home. I guess since it is missing that none of my links work and something is messed up. I just wanna know how to fix all that. If you need further clarification I have added all of my files in example, somwhat like what you posted in your original post.

Plz help!

Attached Files

Community Member, 121 Posts

7 July 2011 at 6:41am

Hi Mac

Not sure sure about the homepage issue, sounds like you don't have one in place though. Silverstripe forces you to always have a homepage I think so even if the navigation name isn't home the url has to be home.

On LOTD.php your link function doesn't do anything

 public function Link() {
      return DataObject::get_one("LOTDPage")->Link() ."#term".$this->ID;

it's calling your LOTDPage then just telling it the term ID but not telling it what to do with it. As a start you need to change in LOTDPage
static $allowed_actions = array(

static $allowed_actions = array(

and the link function in LOTD to

public function Link() 
   		if($Page = DataObject::get_one("LOTDPage "))
      		return $Page->Link() ."ShowLOTD /".$this->ID; 

I haven't tested any of this but thats what it looks like on first glance


Community Member, 143 Posts

10 January 2012 at 2:14pm

Edited: 10/01/2012 2:14pm

Hi to all, i am trying to get this thing straightened out: Getting my customs textfields to become searcheabled. I like the simplicity of populating the $Metatags or $Description with text taken from my customs textfields. As those ($Metatags and $Description) are searcheabled, this does the trick. But HOW and WHERE to do that?

I am no PHP expert, but in plain text or back to my ActionScipt 3 days, that would be like this:

$Metatags.text = $Nom.text + $Prenom.text + $Entreprise.text

Where $Nom, $Prenom, $Entreprise are my custom textfields.

I KNOW THIS ISNT IT, but that what i want!

- - -

Any help appreciated.



Community Member, 121 Posts

13 January 2012 at 9:01am

Edited: 13/01/2012 9:17am

I wanted to add in my information from some textfields columnOne and ColumnTwo so i used below. You might want to read up a little on PHP classes and objects it will make it a lot easier to understand.

function onBeforeWrite() { 
		parent::onBeforeWrite ();
		if (strlen(trim($this->record['MetaDescription']))<1){
		$this->record['MetaDescription']=$this->Content.' '.$this->ColumnOne.' '.$this->ColumnTwo.' '.$this->ColumnThree.' '.$this->BottomContent;