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.

Form Questions

use PopulateTemplate to email form content, need help???


Reply

4 Posts   2293 Views

Avatar
Vesalius

20 December 2008 at 10:54am Community Member, 2 Posts

I've made a custom form which I want to mail and am using PopulateTemplate to format this mail however I get the following error testing in a wamp environment.:

FATAL ERROR: Object::__call() Method 'populateTemplate' not found in class ''
At line 199 in C:\wamp\www\silverstripe\sapphire\core\Object.php

user_error(Object::__call() Method 'populateTemplate' not found in class '',256)
line 199 of Object.php

Object->__call(populateTemplate,Array)
Email->populateTemplate(Array)
line 168 of ReceptenPage.php

ReceptenPage_Controller->doReceptAanvraagForm(Array,Form)
line 238 of Controller.php

Controller->run(Array)
line 22 of ModelAsController.php

ModelAsController->run(Array)
line 104 of Director.php

Director::direct(/uitproberen/)
line 158 of main.php

Context

This is my code and I can't find where I went wrong, I've made a ReceptTemplate.ss in mysite/templates/email:

   function doReceptAanvraagForm($data, $form) {

      $email = new Email(
         $from = $data['email'],
         $to = "mymailadres@gmail.com",
         $subject = "Receptaanvraag"
      );
      $email->ss_template = "ReceptTemplate";
      $templateData = array(
      "Anaam" => $data["Anaam"],
         "Vnaam" => $data["Vnaam"]
      );
      $email->populateTemplate($templateData);
      $email->send();

      // Redirect to a page thanking people for registering
      Director::redirect('uitproberen/');
   }

Avatar
dio5

27 December 2008 at 11:10pm (Last edited: 27 December 2008 11:11pm), Community Member, 501 Posts

Which version of Silverstripe are you using?

I think pre 2.3 you had to use new Email_Template instead of new Email. The Email_Template was a subclass of Email.

In 2.3 this has been changed and I think it was all merged into one class Email, so if you're still using an older version, populateTemplate will not be a method of Email.

The docs are already for 2.3, so this is pretty confusing.

Avatar
bebabeba

4 February 2009 at 5:57am Community Member, 192 Posts

Hi!
I have the same problem and I change Email with Email_Template but in this way mail don't go to sender..With Email was ok. I have v2.2.2

Avatar
Fuzz10

4 February 2009 at 10:47am Community Member, 787 Posts

I noticed this as well....

It looks like you need to use email_template in 2.2.2 and Email in 2.3 ....