Jump to:

1969 Posts in 1272 Topics by 606 members

Form Questions

SilverStripe Forums » Form Questions » Legend

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

Page: 1
Go to End
Author Topic: 1518 Views
  • Harley
    Avatar
    Community Member
    153 Posts

    Legend Link to this post

    Basic question, how do I set a legend on a fieldset?

    To be more specific I am using a multiform form if it makes any difference.

    Thanks

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Legend Link to this post

    This is from the 2.3 Changelog, but I can't find any refrence to it the API

    A <legend> element has been added before any <fieldset> in all SilverStripe forms. SearchForm.ss and Form.ss are where it has been added. This now validates the form HTML for W3C compliance. Please verify that your forms visually look okay after upgrading. Legend can be set by calling →setLegend(’my legend here’) on your Form object.

    http://doc.silverstripe.org/doku.php?id=upgrading:2.3.0&s=fieldset%20legend#notable_feature_changes.

    But if you're using multform you can also specify a custom form template and then just code it in yourself.

  • edi2lopez
    Avatar
    Community Member
    6 Posts

    Re: Legend Link to this post

    Were you able to add <legend> tag to User Forms Module? I am trying to do it in User Forms Module [v0.3.0] without any luck. Please Let me know. Thanks

  • zenmonkey
    Avatar
    Community Member
    524 Posts

    Re: Legend Link to this post

    I use custom templates for most of my forms so I set the legend in the .ss file]

    Cheers,

  • web2works
    Avatar
    Community Member
    50 Posts

    Re: Legend Link to this post

    Better late than never, this is my example form so show how to set the legend.

    <?php

    class EnquiryForm extends Form {

    function __construct($controller, $name) {
       
    $fields = new FieldSet(
    new TextField('name', 'Name', 'Name:'),
    new EmailField('email', 'Email', 'Email:'),
    new PhoneNumberField('tel', 'Tel', 'Tel:'),
    new TextField('brand', 'Brand', 'Brand:'),
    new TextareaField('desc', 'Description', 5, 10, 'Description:'),
    new SimpleImageField('image', 'Add image', 'Add image:')
    );

    $actions = new FieldSet(
    new FormAction('submit', 'Submit')
    );

    $validator = new RequiredFields('Name', 'Email', 'Comments');
       
    $legend = parent::setLegend("Parts enquiry...");

    parent::__construct($controller, $name, $fields, $actions, $validator);
    }

    function forTemplate() {
    return $this->renderWith(array(
    $this->class,
    'Form'
    ));
    }

    function submit($data, $form) {
    // do stuff here
    }

    }

    ?>

    1518 Views
Page: 1
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.