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.

Form Questions

Custom form template


Reply

7 Posts   3115 Views

Avatar
Mo

11 August 2009 at 5:32am Community Member, 509 Posts

Hi All,

I have created a new form class, as per: http://doc.silverstripe.com/doku.php?id=form#using_a_custom_template

I may be being a bit simple, but how do I then return that form in my page controller?

Cheers,

Mo

Avatar
Mo

11 August 2009 at 9:13pm (Last edited: 11 August 2009 9:14pm), Community Member, 509 Posts

Hmm, I was obviously being a bit dense - All you have to do is add:

public function FormClass() {
   return new FormClass($this,'FormClass');
}

To your page controller and then:

$FormClass

To your page template file

Hope this helps someone,

Mo

Avatar
Mo

11 August 2009 at 10:09pm Community Member, 509 Posts

Moving on from this actually, if you have a custom form template you can use $dataFieldByName(FieldName) to generate the correct form field in your template.

Is there any way of doing this with a form label? I have looked through the Form class and cant see anything obvious. Anyone done anything similar?

Mo

Avatar
biapar

17 December 2009 at 2:09am Forum Moderator, 435 Posts

Do you made FormClass page template file?

Avatar
Mo

18 December 2009 at 5:00am Community Member, 509 Posts

Sorry biapar, I am not sure what you mean?

Avatar
patjnr

11 January 2010 at 11:51pm Community Member, 101 Posts

@ biapar yes you create the template FormClass and save it in includes.

Avatar
biapar

16 October 2010 at 9:48pm Forum Moderator, 435 Posts

I think that SS team would to write this into Custom template help page...

public function FormClass() {
return new FormClass($this,'FormClass');
}

To your page controller and then:

$FormClass

To your page template file