mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #855 from 3Dgoo/feature/subjects-with-fields
Allow form fields in email subjects
This commit is contained in:
commit
df918cac8b
@ -364,10 +364,10 @@ JS
|
|||||||
if ($submittedFormField && trim($submittedFormField->Value)) {
|
if ($submittedFormField && trim($submittedFormField->Value)) {
|
||||||
$email->setSubject($submittedFormField->Value);
|
$email->setSubject($submittedFormField->Value);
|
||||||
} else {
|
} else {
|
||||||
$email->setSubject($recipient->EmailSubject);
|
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$email->setSubject($recipient->EmailSubject);
|
$email->setSubject(SSViewer::execute_string($recipient->EmailSubject, $mergeFields));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('updateEmail', $email, $recipient, $emailData);
|
$this->extend('updateEmail', $email, $recipient, $emailData);
|
||||||
|
@ -11,6 +11,7 @@ use SilverStripe\Forms\FormAction;
|
|||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\UserForms\Control\UserDefinedFormController;
|
use SilverStripe\UserForms\Control\UserDefinedFormController;
|
||||||
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
use SilverStripe\UserForms\Model\EditableFormField\EditableTextField;
|
||||||
|
use SilverStripe\UserForms\Model\Recipient\EmailRecipient;
|
||||||
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
|
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
|
||||||
use SilverStripe\UserForms\Model\UserDefinedForm;
|
use SilverStripe\UserForms\Model\UserDefinedForm;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
@ -51,10 +52,10 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
|
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
|
||||||
|
|
||||||
// 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',
|
||||||
'Title' => 'Basic Text Field'
|
'Title' => 'Basic Text Field'
|
||||||
],
|
],
|
||||||
@ -332,4 +333,38 @@ class UserDefinedFormControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
$this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
|
$this->assertEquals((string) $action[0]['value'], "Submit", "Submit button has default text");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testRecipientSubjectMergeFields()
|
||||||
|
{
|
||||||
|
$form = $this->setupFormFrontend();
|
||||||
|
|
||||||
|
$recipient = $this->objFromFixture(EmailRecipient::class, 'recipient-1');
|
||||||
|
$recipient->EmailSubject = 'Email Subject: $basic_text_name';
|
||||||
|
$recipient->write();
|
||||||
|
|
||||||
|
$this->autoFollowRedirection = false;
|
||||||
|
$this->clearEmails();
|
||||||
|
|
||||||
|
// load the form
|
||||||
|
$this->get($form->URLSegment);
|
||||||
|
|
||||||
|
$field = $this->objFromFixture(EditableTextField::class, 'basic-text');
|
||||||
|
|
||||||
|
$response = $this->submitForm('UserForm_Form_' . $form->ID, null, [$field->Name => 'Basic Value']);
|
||||||
|
|
||||||
|
// should have a submitted form field now
|
||||||
|
$submitted = DataObject::get(SubmittedFormField::class, "\"Name\" = 'basic_text_name'");
|
||||||
|
$this->assertListAllMatch(
|
||||||
|
[
|
||||||
|
'Name' => 'basic_text_name',
|
||||||
|
'Value' => 'Basic Value',
|
||||||
|
'Title' => 'Basic Text Field'
|
||||||
|
],
|
||||||
|
$submitted
|
||||||
|
);
|
||||||
|
|
||||||
|
// check emails
|
||||||
|
$this->assertEmailSent('test@example.com', 'no-reply@example.com', 'Email Subject: Basic Value');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
|
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
|
||||||
basic-text:
|
basic-text:
|
||||||
Name: basic-text-name
|
Name: basic_text_name
|
||||||
Title: Basic Text Field
|
Title: Basic Text Field
|
||||||
|
|
||||||
basic-text-2:
|
basic-text-2:
|
||||||
Name: basic-text-name
|
Name: basic_text_name
|
||||||
Title: Basic Text Field
|
Title: Basic Text Field
|
||||||
|
|
||||||
required-text:
|
required-text:
|
||||||
|
@ -63,11 +63,11 @@ SilverStripe\UserForms\Model\EditableFormField\EditableOption:
|
|||||||
|
|
||||||
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
|
SilverStripe\UserForms\Model\EditableFormField\EditableTextField:
|
||||||
basic-text:
|
basic-text:
|
||||||
Name: basic-text-name
|
Name: basic_text_name
|
||||||
Title: Basic Text Field
|
Title: Basic Text Field
|
||||||
|
|
||||||
basic-text-2:
|
basic-text-2:
|
||||||
Name: basic-text-name
|
Name: basic_text_name
|
||||||
Title: Basic Text Field
|
Title: Basic Text Field
|
||||||
|
|
||||||
your-name-field:
|
your-name-field:
|
||||||
|
Loading…
Reference in New Issue
Block a user