mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Include merge fields in plain text emails
This commit is contained in:
parent
c71cf11a8e
commit
52e678c6e7
@ -345,6 +345,8 @@ JS
|
|||||||
// Add specific template data for the current recipient
|
// Add specific template data for the current recipient
|
||||||
$emailData['HideFormData'] = (bool) $recipient->HideFormData;
|
$emailData['HideFormData'] = (bool) $recipient->HideFormData;
|
||||||
// Include any parsed merge field references from the CMS editor - this is already escaped
|
// Include any parsed merge field references from the CMS editor - this is already escaped
|
||||||
|
// This string substitution works for both HTML and plain text emails.
|
||||||
|
// $recipient->getEmailBodyContent() will retrieve the relevant version of the email
|
||||||
$emailData['Body'] = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
|
$emailData['Body'] = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
|
||||||
|
|
||||||
// Push the template data to the Email's data
|
// Push the template data to the Email's data
|
||||||
@ -414,7 +416,8 @@ JS
|
|||||||
$this->extend('updateEmail', $email, $recipient, $emailData);
|
$this->extend('updateEmail', $email, $recipient, $emailData);
|
||||||
|
|
||||||
if ((bool)$recipient->SendPlain) {
|
if ((bool)$recipient->SendPlain) {
|
||||||
$body = strip_tags($recipient->getEmailBodyContent()) . "\n";
|
// decode previously encoded html tags because the email is being sent as text/plain
|
||||||
|
$body = html_entity_decode($emailData['Body']) . "\n";
|
||||||
if (isset($emailData['Fields']) && !$emailData['HideFormData']) {
|
if (isset($emailData['Fields']) && !$emailData['HideFormData']) {
|
||||||
foreach ($emailData['Fields'] as $field) {
|
foreach ($emailData['Fields'] as $field) {
|
||||||
if ($field instanceof SubmittedFileField) {
|
if ($field instanceof SubmittedFileField) {
|
||||||
|
@ -68,16 +68,18 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
// load the form
|
// load the form
|
||||||
$this->get($form->URLSegment);
|
$this->get($form->URLSegment);
|
||||||
|
|
||||||
|
/** @var EditableTextField $field */
|
||||||
$field = $this->objFromFixture(EditableTextField::class, 'basic-text');
|
$field = $this->objFromFixture(EditableTextField::class, 'basic-text');
|
||||||
|
|
||||||
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
|
$data = [$field->Name => 'Basic Value <b>HTML</b>'];
|
||||||
|
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, $data);
|
||||||
|
|
||||||
// should have a submitted form field now
|
// should have a submitted form field now
|
||||||
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic_text_name'");
|
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic_text_name'");
|
||||||
$this->assertListAllMatch(
|
$this->assertListAllMatch(
|
||||||
[
|
[
|
||||||
'Name' => 'basic_text_name',
|
'Name' => 'basic_text_name',
|
||||||
'Value' => 'Basic Value',
|
'Value' => 'Basic Value <b>HTML</b>',
|
||||||
'Title' => 'Basic Text Field'
|
'Title' => 'Basic Text Field'
|
||||||
],
|
],
|
||||||
$submitted
|
$submitted
|
||||||
@ -93,8 +95,12 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
$this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
|
$this->assertEquals('Basic Text Field', (string) $title[0], 'Email contains the field name');
|
||||||
|
|
||||||
|
// submitted html tags are escaped for the html value
|
||||||
|
$value = 'class="readonly">My body html Basic Value <b>HTML</b></span>';
|
||||||
|
$this->assertTrue(strpos($email['Content'], $value) !== false, 'Email contains the merge field value');
|
||||||
|
|
||||||
$value = $parser->getBySelector('dd');
|
$value = $parser->getBySelector('dd');
|
||||||
$this->assertEquals('Basic Value', (string) $value[0], 'Email contains the value');
|
$this->assertEquals('Basic Value <b>HTML</b>', (string) $value[0], 'Email contains the value');
|
||||||
|
|
||||||
// no html
|
// no html
|
||||||
$this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
|
$this->assertEmailSent('nohtml@example.com', 'no-reply@example.com', 'Email Subject');
|
||||||
@ -102,6 +108,10 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
$this->assertContains('Basic Text Field: Basic Value', $nohtml['Content'], 'Email contains no html');
|
$this->assertContains('Basic Text Field: Basic Value', $nohtml['Content'], 'Email contains no html');
|
||||||
|
|
||||||
|
// submitted html tags are not escaped because the email is being sent as text/plain
|
||||||
|
$value = 'My body text Basic Value <b>HTML</b>';
|
||||||
|
$this->assertContains($value, $nohtml['Content'], 'Email contains the merge field value');
|
||||||
|
|
||||||
// no data
|
// no data
|
||||||
$this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
$this->assertEmailSent('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||||
$nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
$nodata = $this->findEmail('nodata@example.com', 'no-reply@example.com', 'Email Subject');
|
||||||
|
@ -317,12 +317,14 @@ SilverStripe\UserForms\Model\Recipient\EmailRecipient:
|
|||||||
EmailAddress: test@example.com
|
EmailAddress: test@example.com
|
||||||
EmailSubject: Email Subject
|
EmailSubject: Email Subject
|
||||||
EmailFrom: no-reply@example.com
|
EmailFrom: no-reply@example.com
|
||||||
|
EmailBodyHtml: '<div class="form__field-holder"><span id="Form_ItemEditForm_MergeField" class="readonly">My body html $basic_text_name</span></div>'
|
||||||
|
|
||||||
no-html:
|
no-html:
|
||||||
EmailAddress: nohtml@example.com
|
EmailAddress: nohtml@example.com
|
||||||
EmailSubject: Email Subject
|
EmailSubject: Email Subject
|
||||||
EmailFrom: no-reply@example.com
|
EmailFrom: no-reply@example.com
|
||||||
SendPlain: true
|
SendPlain: true
|
||||||
|
EmailBody: 'My body text $basic_text_name'
|
||||||
|
|
||||||
no-data:
|
no-data:
|
||||||
EmailAddress: nodata@example.com
|
EmailAddress: nodata@example.com
|
||||||
|
Loading…
Reference in New Issue
Block a user