Jump to:

10850 Posts in 2517 Topics by 1793 members

All other Modules

SilverStripe Forums » All other Modules » Extending UserDefinedForm

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1433 Views
  • Juanitou
    Avatar
    Community Member
    322 Posts

    Extending UserDefinedForm Link to this post

    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

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: Extending UserDefinedForm Link to this post

    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…

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Extending UserDefinedForm Link to this post

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

  • Juanitou
    Avatar
    Community Member
    322 Posts

    Re: Extending UserDefinedForm Link to this post

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

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