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.

Form Questions

How to take out 'Form Legend' tag


Go to End
Reply

16 Posts   3627 Views

Avatar
kudesign

22 December 2008 at 2:28pm Community Member, 64 Posts

I have followed the tutorial on how to create a site search form. For some reason, it created a 'legend' tag with a border around the search form.

I found a tip from the forum, to create a new SearchForm.ss

<form $FormAttributes>
<% control Fields %>
$FieldHolder
<% end_control %>

<% control Actions %>
$Field
<% end_control %>
</form>

Does anyone know how to remove this tag easily, without having to write a new template?

Thanks!

Avatar
dio5

27 December 2008 at 10:32pm Community Member, 501 Posts

I don't think there is a way.

Previous versions of Silverstripe did not have a legend tag at all in the forms - which made them fail html validation.

If you want to get rid of the border, you could probably just do that with CSS:

legend{ display:none; }

or something...

I'm not sure why a legend would create a border by default - that sounds more like something that a <fieldset> would do...

Avatar
BuddhaSource

24 January 2009 at 6:52pm Community Member, 57 Posts

Yes would really like that.

I wanted to have little more control over the looks and feel of the search text box.
Woluld be glad if someone can point out where to look for.

Avatar
ianpiper

27 January 2009 at 11:52pm Community Member, 32 Posts

I am having the same issue, but I have solved part of it.

You can get rid of the border by adding a CSS element for the fieldset (which is where the border is being set by the user agent) :

#Header form fieldset {
   border: none;
}

As for the word "Search" appearing, I am a bit baffled. I've tried tracking back to see where this originates, but no luck. I looked at SearchForm.php but that doesn't seem to be the source.

Can anyone tell me where in the code this caption gets inserted?

Ian.
--

Avatar
dio5

28 January 2009 at 12:04am (Last edited: 28 January 2009 12:05am), Community Member, 501 Posts

'Search' comes from the code in your controller probably something like

$fields = new FieldSet(
            new TextField("Search","Search");
);

The second 'search' is the label.

For changing the look and feel of it, CSS is really what you're looking for.

Setting a legend can be done with

$FormObject->setLegend("Value");

Avatar
ianpiper

28 January 2009 at 12:26am Community Member, 32 Posts

No, I don't think that is the source. I have already removed those references from the controller. Here is my code in the controller:

function SearchForm() {
$searchText = isset($this->Query) ? $this->Query : '';   
$fields = new FieldSet(
new TextField("", "", $searchText)
);
$actions = new FieldSet(
new FormAction('results', 'Search')
);
return new SearchForm($this, "SearchForm", $fields, $actions);
}

I notice the syntax of the TextField method is different in your suggestion. But I tried pasting in what you wrote and it made no difference.

Regarding the setLegend command, how do you use this? I tried

$fields->setLegend("")

in the SearchForm function, but this throws a Big Red Error "Method 'setLegend' not found in class 'FieldSet'.

Any ideas where I am going wrong?

Thanks,

Ian.
--

Avatar
dio5

28 January 2009 at 12:31am Community Member, 501 Posts

Not sure about which search you're talking?

Do you have some url or code to look into?

The textfield 'Search' sets the label, the 'Search' on the button is by the action.

Avatar
ianpiper

28 January 2009 at 4:00am Community Member, 32 Posts

I have been following the tutorials from the silverstripe.org website. Tutorial 4 is the one that deals with creating a site search. I've basically abandoned worrying about this unwanted caption for now - I'll come back to it when I have some spare time. Thanks for looking anyway.

Ian.
--

Go to Top