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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Custom email template


Go to End


7 Posts   3549 Views

Avatar
karibe

Community Member, 56 Posts

29 October 2007 at 12:47pm

Hello

I'm looking for solution how to add custom email template on user defined form ( contact form ) submits .

When form is emailed it looks like it using Page.ss which is bad for me:)
How to add customized template for emailed submitted user form?

Avatar
Sean

Forum Moderator, 922 Posts

29 October 2007 at 3:07pm

There's 2 solutions:

1. You make a contact form in code, rather than use the 'contact form' in the CMS - this way you get full control over making it. See the 3rd tutorial for more information on this.

2. Subclass UserDefinedForm, and hack the code so it chooses a different template. (Not the best solution).

Cheers,
Sean

Avatar
blacky

3 Posts

30 October 2007 at 10:30pm

can u help to place dropdown controls from middle of the page ... help me please

Avatar
karibe

Community Member, 56 Posts

30 October 2007 at 11:10pm

OK, I used http://doc.silverstripe.com/doku.php?id=email_template end works almost perfect but there are three problems:

1. How to add translated validation messages? Page is in Polish and have to translate validation messages
2. How to add proper encoding to email? I have bad characters when email is submitted
3. How to add confirmation message that the email has been send

function doContactForm ( $data, $form )
{
$submission = new ContactFormSubmission();
$form->saveInto($submission);
$submission->write();
// send email
$email = new Email_Template();
$email->ss_template = "ContactFormEmail";
$email->populateTemplate($submission);
$email->subject = $submission->val( "Subject" );
$email->from = $submission->val("Email");
$email->to = "info@somedomain.pl";
$email->send();
// ---
Director::redirectBack();
}

Template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
</head>
<body>

<p class="body">

<p>Wiadomość wysłana przez $Name z formularza kontaktowego:</p>

$Content
</p>

</body>
</html>

Avatar
karibe

Community Member, 56 Posts

30 October 2007 at 11:48pm

Ok now I need only two answers:)

3. How to add confirmation message that the email has been send?

I had to add SubmittedContactArticlePage.ss and works perfect:)

Avatar
Sean

Forum Moderator, 922 Posts

31 October 2007 at 9:43am

Just before Director::redirectBack() you can call:

$form->sessionMessage('Thanks, you've been signed up', 'good');

Cheers,
Sean

Avatar
karibe

Community Member, 56 Posts

1 November 2007 at 12:09am

Great

Are there some messages like 'good' for replacing validation messages?