Jump to:

10987 Posts in 2724 Topics by 1817 members

All other Modules

SilverStripe Forums » All other Modules » Extend Userforms

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 186 Views
  • merrick_sd
    Community Member
    95 Posts

    Extend Userforms Link to this post

    I'm after a tutorial / advice on how to extend userforms and use updateEmailData rather than edit line 985/990 of UserDefinedForm.php

    $emailData = array(
          //'RegisteredOffice' => Page_Controller::RegisteredOffice(), adding this here would be easy
          "Sender" => Member::currentUser(),
          "Fields" => $submittedFields

    $this->extend('updateEmailData', $emailData, $attachments);



    mysite -> _config.php

    Object::add_extension('UserDefinedForm_Controller', 'MyUserDefinedFormExtension');

    mysite -> code -> MyUserDefinedFormExtension.php

    class MyUserDefinedFormExtension extends Extension {
       static $allowed_actions = array(
    function updateEmailData($emailData, $attachments){
          $attachments = null;
          $testp = "i am testing";
          //UserDefinedForm_Controller::$emailData = array("TestPass" => $testp);
          $emailData = array("TestPass" => $testp);
          //echo "update called".$emailData['TestPass']."";
          return $emailData;

    SubmittedFormEmail.ss (email template)

    TestPass: $TestPass

    If I move TestPass into the emailData array in UserDefinedForm.php it works.
    updateEmailData is being called though on MyUserDefinedFormExtension.php as if I print it shows the TestPass variable

  • merrick_sd
    Community Member
    95 Posts

    Re: Extend Userforms Link to this post

    In case it helps anyone else

    mysite >_config.php

    Object::add_extension('UserDefinedForm_Controller', 'MyUserDefinedFormExtension');

    mysite > code > MysUserDefinedFormExtension.php

    * An Extension to the UserDefinedForm submission process
    * @package userforms
    * Reasoning:
    * 1. do not touch source code of userforms module.
    * 2. I want to pass data which is captured via the functions in my Page_Controller into the SubmittedFormEmail.ss template
          eg <% loop RegisteredOffice %> $Adddress1 <% end_loop %>

    Mysite > _config.php contains the following to register this Extended Class
    Object::add_extension('UserDefinedForm_Controller', 'MyUserDefinedFormExtension');

    class MyUserDefinedFormExtension extends Extension {
       private static $allowed_actions = array(

       public function updateEmailData($emailData, $attachments){
          $attachments = null;
          $registeredoffices = Controller::curr()->RegisteredOffice();
          $footericons = Controller::curr()->getAllFooterIcons();
          $NewData = $emailData;
          $NewData["RegisteredOffice"] = $registeredoffices;
          $NewData["AllFooterIcons"] = $footericons;
          $emailData = $NewData;
          $this->emailData = $NewData;

       return $this->emailData; //return emailData
       public function updateEmail($email, $recipient, $emailData){
          $emailData = $this->emailData;

    also at http://www.sspaste.com/paste/show/53a82f953bf20

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.