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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Extended UserDefinedForm - Not rendering template


Go to End


5 Posts   2898 Views

Avatar
Double-A-Ron

Community Member, 607 Posts

15 October 2009 at 10:16am

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

Avatar
Willr

Forum Moderator, 5523 Posts

15 October 2009 at 1:16pm

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.

Avatar
Double-A-Ron

Community Member, 607 Posts

15 October 2009 at 1:39pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

15 October 2009 at 1:45pm

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)

Avatar
Double-A-Ron

Community Member, 607 Posts

15 October 2009 at 2:02pm

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