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.

Archive /

Our old forums are still available as a read-only archive.

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

Generating site search / unnecessary html


Go to End


9 Posts   4227 Views

Avatar
superautomatic

Community Member, 53 Posts

4 December 2007 at 6:35am

Hi,

I'm building a site and added the search-functionality from the tutorial. It seems to me that a lot of unnecessary html is added that I would like to remove but don't know how. For example, new TextField("Search", "", $searchText);

generates an extra div: <div id="Search" class="field text nolabel">
and an extra span: <span class="middleColumn">

How do I get rid of those?

Best regards,
Jens

Avatar
Aaron

Community Member, 63 Posts

24 May 2008 at 2:02pm

Boy this is a bit of old thread, but exactly the question I was searching for.

I don't really care about the unnecessary HTML at the moment, but is there a way to create a form element like the search box and assign a custom css class to it?

Cheers
Aaron

Avatar
Sean

Forum Moderator, 922 Posts

24 May 2008 at 3:27pm

In your code where you're generating the actual search field, you could do something like this:

$searchField = new TextField('Search');
$searchField->addExtraClass('myClass');

$fields = new FieldSet(
$searchField
);

See here, for the search tutorial: http://doc.silverstripe.com/doku.php?id=tutorial:4-site-search

Sean

Avatar
bod

Community Member, 72 Posts

22 July 2008 at 6:13am

Hi - I would really like it if someone could let me know the answer to the original posters question? I'm coming across a lot of unanswered questions in the forum :o/...

"generates an extra div: <div id="Search" class="field text nolabel">
and an extra span: <span class="middleColumn"> "

how does one go about getting rid of this html - can't find it in any .ss files - please help!

Avatar
bod

Community Member, 72 Posts

25 July 2008 at 1:30am

Edited: 25/07/2008 1:36am

Well just to update anyone else with this problem searching the board. The only way I could get it to work in the absence of a reply to my post, was to edit the formfield.php file, line 265 to get rid of the div and span tags, (perhaps they shouldn't really be mixed in there as they are for presentation rather than functional elements within form controls, no?).

The comments in the formfield.php did point to using another file DefaultFieldHolder.ss that should be used to implement a custom look, however this isn't elaborated on as to how this is achieved unfortunately. I did try by placing it in my themes folder and doing the flush=1 trick but it didn't appear to get picked up by SS when placed in there so I'm none the wiser as to it's proper usage or context.... :o(

Can anyone from the team help to expand on how this file (DefaultFieldHolder.ss) works to create a custom look to forms in the app please?

Avatar
bod

Community Member, 72 Posts

29 July 2008 at 10:29pm

Actually - scrap that, hacking that file just screws the CMS forms up completely. So that still leaves me with a search form that I need to desperately customise.

Can anyone help with this? Really would appreciate it. Either by using the DefaultFieldHolder.ss or another method please?

Avatar
Double-A-Ron

Community Member, 607 Posts

2 September 2008 at 2:36pm

I ended up just adding the search form, copying the source code that it generates, the replacing it with hard coded HTML and removing everything I didn't want.

Worked for me, and obviously there is no answer to this.

Avatar
camspiers

Community Member, 5 Posts

4 September 2008 at 4:49pm

I know this thread is kind of old but from memory you can extend all the existing classes (ie form fields) and set the template that it renders with. You should do all of this in you own code and templates sections of your site. No need at all to modify the core. Also you can extend to Search Engine overwriting the methods you need to change to make the default search better.

Dio to allow searching in places that are in the sitetree you can add Fulltext to them and then change the Search Engine.

Go to Top