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.

All other Modules /

Discuss all other Modules here.

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

Extending UserDefinedForm


Reply


4 Posts   1542 Views

Avatar
Juanitou

Community Member, 323 Posts

9 June 2009 at 1:09am

Edited: 09/06/2009 2:26am

Hi!

I'm not good at PHP. I'm trying to extend UserDefinedForm for one added feature: being able to count the number of form submissions and print it in the mail message sent to the client.

It's quite easy to get this count done in the page controller (InscriptionsPage.php):

class InscriptionsPage extends UserDefinedForm {

   static $add_action = "formulaire pour divers inscriptions";
   static $icon = "cms/images/treeicons/task";

}
   

class InscriptionsPage_Controller extends UserDefinedForm_Controller {
   
   function InscriptionsResults() {
      $submissions = DataObject::get('SubmittedForm', "ParentID = $this->ID");
      $total = $submissions->Count();
      return $total;
   }

}

Now, in InscriptionsPage.ss I can use $InscriptionResults in order to print the number of submissions (even if I have no use for that), but I'm not being able to use $InscriptionResults in the email submitted to the page owner. Ideally, I'd like to have a specific template for this form, but I'm not even being able to overload the default template SubmittedFormEmailToSubmitter.ss:

class InscriptionsPage_SubmittedFormEmail extends UserDefinedForm_SubmittedFormEmail {
   protected $ss_template = "InscriptionsPage_SubmittedFormEmail";
   
   function __construct() {
      parent::__construct();
      
   }

Could someone please help me in those basic tasks: accessing the function InscriptionsResults() outside the page (i.e. in the email template) and using a specific template instead of the default one for this email.

Thanks in advance,
Juan

Avatar
Juanitou

Community Member, 323 Posts

9 June 2009 at 2:53am

I partially reply to myself:

As the process() function in UserDefinedForm creates a new UserDefinedForm_SubmittedFormEmail, I should override also this function, isn't it? Maybe it's impossible to do what I want by subclassing UserDefinedForm…

Avatar
Willr

Forum Moderator, 5513 Posts

9 June 2009 at 5:56pm

You would almost be better Decorating the form rather then subclassing it - http://doc.silverstripe.com/doku.php?id=dataobjectdecorator

Avatar
Juanitou

Community Member, 323 Posts

10 June 2009 at 4:59am

Thanks willr, I'll try the Decorator, if I ever understand how it works and applies to the email templates… :)