Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Is it possible to pass a class attribute to form labels?

Couldn't find the forms controller in the dashboard / vanilla directories, so hopefully someone will already know this.

Is it possible to pass a class attribute to a form label? I can see them being rendered in the view like this:
$this->Form->Label('Username', 'Name')
… but my experiments to pass an additional class have been unsuccessful (tried passing a key/value array as the third parameter and that produced a very interesting effect!).

Cheers,

Pete

Tagged:

Comments

  • Should work

    $this->Form->Label('Username', 'Name', array('class'=>'YourClass'));
    

    grep is your friend.

  • hgtonighthgtonight ∞ · New Moderator

    You should be able to pass an array of attribute => value pairs in as the third argument. Some attributes on the form object are reserved due to the nature of the class. None of the following attributes can be set as of 2.0.18.10: 'id', 'name', 'value', 'method', 'action', 'type', 'for', 'multiline', 'default', 'textfield', 'valuefield', 'includenull', 'yearrange', 'fields', and 'inlineerrors'.

    This means you can add a class like so: echo $this->Form->Label('Text Shown To User', 'Fieldname', array('class' => 'MySuperCoolClass'));

    For more information, the form object is of type Gdn_Form and is defined in /library/core/class.form.php.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Thanks. I thought I'd tried that, but obviously must have got my syntax wrong since it's now working. ;-)

Sign In or Register to comment.