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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

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

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


Go to End


4 Posts   3334 Views

Avatar
Vesalius

Community Member, 2 Posts

20 December 2008 at 10:54am

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

Community Member, 501 Posts

27 December 2008 at 11:10pm

Edited: 27/12/2008 11:11pm

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

Community Member, 193 Posts

4 February 2009 at 5:57am

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

Community Member, 791 Posts

4 February 2009 at 10:47am

I noticed this as well....

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