Jump to:

10979 Posts in 2722 Topics by 1815 members

All other Modules

SilverStripe Forums » All other Modules » Extended UserDefinedForm - Not rendering template

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1887 Views
  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Extended UserDefinedForm - Not rendering template Link to this post

    Hi all,

    I have made a new page type, extending a standard UserDefinedForm installation:

    class SpecialOffersForm extends UserDefinedForm {
    /**
    * @var String Add Action in the CMS
    */
    static $add_action = "A Special Offers Form";

    /**
    * @var String Icon for the User Defined Form in the CMS. Without the extension
    */
    static $icon = "cms/images/treeicons/task";

    /**
    * @var String What level permission is needed to edit / add
    */
    static $need_permission = 'ADMIN';

    /**
    * @var Array Fields on the user defined form page.
    */
    static $db = array(

    );

    /**
    * @var Array Default values of variables when this page is created
    */
    static $defaults = array(
    'Content' => '$SpecialOffersForm',
    'DisableSaveSubmissions' => 0,
    'OnCompleteMessage' => '<p>Thanks, we\'ve received your submission.</p>'
    );

    ....

    }

    I extended it as this form will always have a default set of fields and I have worked out how to automatically create these feilds when a new SpecialOffersForm is created in the CMS. This is so the client does not need to go through the process of setting up the form every time they create a page of this type.

    Works fine in the CMS, however when I go to look at it on the frontend, all I get is a blank white page with "SpecialOffersForm" printed. No HTML in the source, so the default Page.ss is not being loaded at all.

    Am I wrong to assume that because the above class extends UserDefinedForm, which in turn extends Page, that my new class will be rendered using Page.ss

    Ta
    Aaron

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Extended UserDefinedForm - Not rendering template Link to this post

    Have you got a SpecialOffersForm_Controller extends UserDefinedForm { in your file?

    Also because you extend UserDefinedForm you don't need to redefine everything in UserDefinedForm.php eg $icon, $permission. It will inherit the values already.

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Extended UserDefinedForm - Not rendering template Link to this post

    Hiya Will,

    That was the first thing I looked at. I didn't at first, then I added:

    class SpecialOffersForm_Controller extends UserDefinedForm_Controller {

    public function init() {
    parent::init();
    }

    }

    No luck unfortunately. Any other ideas?

    Yeah I'm aware I don't need to redefine all of those statics. I only did that in case I want to extend further.

    Ta
    Aaron

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Extended UserDefinedForm - Not rendering template Link to this post

    Rendering just the white page with the classname usually means something with the controller is not configured correctly. Can't remember the exact fix but you might like to check that Page_Controllers init() method gets called (so no typos)

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: Extended UserDefinedForm - Not rendering template Link to this post

    Thanks Will,

    Got it working, but unsure how. I just made a new AaronsForm class in the exact same way but with minimal code, did a Dev/build for that, and it worked.

    Changed the same page to the orginal "SpecialOffersForm" type and it worked too.

    I must have done something code-wise in the class that required a dev/build.

    Ta
    Aaron

    1887 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.