10390 Posts in 2201 Topics by 1712 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1260 Views |
-
Extending UserDefinedForm

9 June 2009 at 1:09am Last edited: 9 June 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 -
Re: Extending UserDefinedForm

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…
-
Re: Extending UserDefinedForm

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
-
Re: Extending UserDefinedForm

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…
| 1260 Views | ||
|
Page:
1
|
Go to Top |

