Merge pull request #1134 from xini/hide-invisible-fields-from-emails

ENH Add config to hide invisible fields from email output
This commit is contained in:
Michal Kleiner 2022-03-15 14:41:57 +13:00 committed by GitHub
commit 6826489295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 6 deletions

View File

@ -256,6 +256,9 @@ JS
} }
} }
// set visibility flag according to display rules
$submittedField->Displayed = $field->isDisplayed($data);
if (!empty($data[$field->Name])) { if (!empty($data[$field->Name])) {
if (in_array(EditableFileField::class, $field->getClassAncestry())) { if (in_array(EditableFileField::class, $field->getClassAncestry())) {
if (!empty($_FILES[$field->Name]['name'])) { if (!empty($_FILES[$field->Name]['name'])) {
@ -305,6 +308,8 @@ JS
$submittedFields->push($submittedField); $submittedFields->push($submittedField);
} }
$visibleSubmittedFields = $submittedFields->filter('Displayed', true);
$emailData = [ $emailData = [
'Sender' => Security::getCurrentUser(), 'Sender' => Security::getCurrentUser(),
'HideFormData' => false, 'HideFormData' => false,
@ -350,6 +355,10 @@ JS
// This string substitution works for both HTML and plain text emails. // This string substitution works for both HTML and plain text emails.
// $recipient->getEmailBodyContent() will retrieve the relevant version of the email // $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);
// only include visible fields if recipient visibility flag is set
if ((bool) $recipient->HideInvisibleFields) {
$emailData['Fields'] = $visibleSubmittedFields;
}
// Push the template data to the Email's data // Push the template data to the Email's data
foreach ($emailData as $key => $value) { foreach ($emailData as $key => $value) {

View File

@ -80,6 +80,7 @@ class EmailRecipient extends DataObject
'EmailTemplate' => 'Varchar', 'EmailTemplate' => 'Varchar',
'SendPlain' => 'Boolean', 'SendPlain' => 'Boolean',
'HideFormData' => 'Boolean', 'HideFormData' => 'Boolean',
'HideInvisibleFields' => 'Boolean',
'CustomRulesCondition' => 'Enum("And,Or")' 'CustomRulesCondition' => 'Enum("And,Or")'
]; ];
@ -303,6 +304,10 @@ class EmailRecipient extends DataObject
'HideFormData', 'HideFormData',
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.HIDEFORMDATA', 'Hide form data from email?') _t('SilverStripe\\UserForms\\Model\\UserDefinedForm.HIDEFORMDATA', 'Hide form data from email?')
), ),
CheckboxField::create(
'HideInvisibleFields',
_t('SilverStripe\\UserForms\\Model\\UserDefinedForm.HIDEINVISIBLEFIELDS', 'Hide invisible fields from email?')
),
CheckboxField::create( CheckboxField::create(
'SendPlain', 'SendPlain',
_t( _t(

View File

@ -19,7 +19,8 @@ class SubmittedFormField extends DataObject
private static $db = [ private static $db = [
'Name' => 'Varchar', 'Name' => 'Varchar',
'Value' => 'Text', 'Value' => 'Text',
'Title' => 'Varchar(255)' 'Title' => 'Varchar(255)',
'Displayed' => 'Boolean',
]; ];
private static $has_one = [ private static $has_one = [

View File

@ -50,6 +50,10 @@ In this field you can add a custom message to add to the email
You can check this if you do not wish for the email recipient to see the form submission's data in the email. You can check this if you do not wish for the email recipient to see the form submission's data in the email.
#### Hide invisible fields from email?
You can check this if you want to hide the fields from the email that were invisible to the user according to the display rules set up for the form fields.
#### Send email as plain text? #### Send email as plain text?
You can check this if you want to remove all of the HTML from the email, this means the email You can check this if you want to remove all of the HTML from the email, this means the email

View File

@ -277,6 +277,7 @@ en:
EmailFromContent: 'The from address allows you to set who the email comes from. On most servers this will need to be set to an email address on the same domain name as your site. For example on yoursite.com the from address may need to be something@yoursite.com. You can however, set any email address you wish as the reply to address.' EmailFromContent: 'The from address allows you to set who the email comes from. On most servers this will need to be set to an email address on the same domain name as your site. For example on yoursite.com the from address may need to be something@yoursite.com. You can however, set any email address you wish as the reply to address.'
FROMADDRESS: 'Send email from' FROMADDRESS: 'Send email from'
HIDEFORMDATA: 'Hide form data from email?' HIDEFORMDATA: 'Hide form data from email?'
HIDEINVISIBLEFIELDS: 'Hide invisible fields from email?'
ORSELECTAFIELDTOUSEASFROM: '.. or select a field to use as reply to address' ORSELECTAFIELDTOUSEASFROM: '.. or select a field to use as reply to address'
ORSELECTAFIELDTOUSEASTO: '.. or select a field to use as the to address' ORSELECTAFIELDTOUSEASTO: '.. or select a field to use as the to address'
PLURALNAME: 'Base Pages' PLURALNAME: 'Base Pages'