Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Form Templates

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2639 Views
  • Nathan Cox
    Community Member
    99 Posts

    Form Templates Link to this post

    Hi, I'm trying to set my site up to use a custom template to display the forms, but I'm having some troubles.

    I tried overwriting Form.ss, but it seems to be used by the CMS as well, so the admin area was all screwed up by the new form template.

    So I put my template into PageForm.ss and changed the page template to use <% include PageForm %> instead of $Form, which works fine (if I put <% control Form %> in it) except that it doesn't work for things like the login page form, since it's rendered with Form.ss but isn't in the Form control.
    I could override LoginForm and change it's forTemplate(), but that would have a problem with the <% control Form %> in the template, and I was wondering if there's a tidier and more consistent way. I thought of overriding the Form class, but I can't do that...if I just subclass it or use Object::useCustomClass('Form', 'PageForm'), things like the LoginForm still won't use it, and I'd rather not hack any of SilverStripe's files.

    Can anyone recommend a nicer way of doing this?

  • lukehumble
    17 Posts

    Re: Form Templates Link to this post

    I would be interested in this as well!

  • Ingo
    Forum Moderator
    801 Posts

    Re: Form Templates Link to this post

    yeah, useCustomClass is way to global for what you're trying to achieve.
    what should your custom template contain that formfields can't handle?
    using CompositeFields with setID()/addClassName(), and using LiteralFields for any raw HTML needed can get you a long way towards customsing forms.
    if you need a different rendering of a specificl FormField, subclass it and change its Field() or FieldHolder() method.
    i don't think there's an easy way to circumvent the <% control Fields %> in a custom template, if thats what you're trying to achieve.

    we've got a a documentation request outstanding for this kind of customizing: http://open.silverstripe.com/ticket/1540

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.