Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » How to take out 'Form Legend' tag

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

Page: 1 2
Go to End
Author Topic: 3563 Views
  • kudesign
    Avatar
    Community Member
    64 Posts

    How to take out 'Form Legend' tag Link to this post

    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!

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    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...

  • BuddhaSource
    Avatar
    Community Member
    57 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    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.

  • ianpiper
    Avatar
    Community Member
    32 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    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.
    --

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    '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");

  • ianpiper
    Avatar
    Community Member
    32 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    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.
    --

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    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.

  • ianpiper
    Avatar
    Community Member
    32 Posts

    Re: How to take out 'Form Legend' tag Link to this post

    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.
    --

    3563 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.