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.

Archive

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

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

Form Templates


Reply

3 Posts   2645 Views

Avatar
Nathan Cox

5 September 2007 at 12:40pm Community Member, 99 Posts

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?

Avatar
lukehumble

2 November 2007 at 5:33am (Last edited: 2 November 2007 5:33am), 17 Posts

I would be interested in this as well!

Avatar
Ingo

4 November 2007 at 3:47pm Forum Moderator, 801 Posts

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