Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Custom form template

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

Page: 1
Go to End
Author Topic: 3088 Views
  • Mo
    Avatar
    Community Member
    508 Posts

    Custom form template Link to this post

    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

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Custom form template Link to this post

    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

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Custom form template Link to this post

    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

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: Custom form template Link to this post

    Do you made FormClass page template file?

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Custom form template Link to this post

    Sorry biapar, I am not sure what you mean?

  • patjnr
    Avatar
    Community Member
    101 Posts

    Re: Custom form template Link to this post

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

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: Custom form template Link to this post

    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

    3088 Views
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.