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

How to take out 'Form Legend' tag


Go to End


16 Posts   6474 Views

Avatar
kudesign

Community Member, 64 Posts

22 December 2008 at 2:28pm

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

Community Member, 501 Posts

27 December 2008 at 10:32pm

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

Community Member, 57 Posts

24 January 2009 at 6:52pm

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

Community Member, 32 Posts

27 January 2009 at 11:52pm

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

Community Member, 501 Posts

28 January 2009 at 12:04am

Edited: 28/01/2009 12:05am

'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

Community Member, 32 Posts

28 January 2009 at 12:26am

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

Community Member, 501 Posts

28 January 2009 at 12:31am

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

Community Member, 32 Posts

28 January 2009 at 4:00am

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