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   3157 Views

Avatar
Mo

Community Member, 510 Posts

11 August 2009 at 5:32am

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

Community Member, 510 Posts

11 August 2009 at 9:13pm

Edited: 11/08/2009 9:14pm

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

Community Member, 510 Posts

11 August 2009 at 10:09pm

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

Forum Moderator, 435 Posts

17 December 2009 at 2:09am

Do you made FormClass page template file?

Avatar
Mo

Community Member, 510 Posts

18 December 2009 at 5:00am

Sorry biapar, I am not sure what you mean?

Avatar
patjnr

Community Member, 101 Posts

11 January 2010 at 11:51pm

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

Avatar
biapar

Forum Moderator, 435 Posts

16 October 2010 at 9:48pm

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