Beautiful Open-Source Form Builder
Enhance form submission handling by adding rich text field support and improving email notification tests. (#1141)
Chirag Chhatralaf788ecbbbea6
diff --git a/api/app/Service/Forms/FormSubmissionFormatter.php b/api/app/Service/Forms/FormSubmissionFormatter.phpindex e8d834f3f..56482fef1 100644--- a/api/app/Service/Forms/FormSubmissionFormatter.php+++ b/api/app/Service/Forms/FormSubmissionFormatter.php@@ -5,8 +5,9 @@ namespace App\Service\Forms;use App\Models\Forms\Form;use App\Service\Storage\FilenameUrlEncoder;use Carbon\Carbon;-use Illuminate\Support\Str;use Illuminate\Support\Facades\URL;+use Illuminate\Support\Str;+use Stevebauman\Purify\Facades\Purify;class FormSubmissionFormatter{@@ -239,6 +240,14 @@ class FormSubmissionFormatter}} elseif ($field['type'] == 'matrix') {$field['value'] = str_replace(' | ', "\n", $this->getMatrixString($data[$field['id']]));+ } elseif ($field['type'] == 'rich_text') {+ $value = $data[$field['id']];+ if (is_string($value) && $value !== '') {+ $field['value'] = Purify::clean($value);+ $field['value_is_html'] = true;+ } else {+ $field['value'] = $value;+ }} elseif (in_array($field['type'], ['files', 'signature'])) {if ($this->outputStringsOnly) {$formId = $this->form->id;diff --git a/api/tests/Feature/Forms/EmailNotificationTest.php b/api/tests/Feature/Forms/EmailNotificationTest.phpindex 156589b24..a4817e0e0 100644--- a/api/tests/Feature/Forms/EmailNotificationTest.php+++ b/api/tests/Feature/Forms/EmailNotificationTest.php@@ -426,3 +426,43 @@ it('resolves mentions for hidden fields in email content when hidden submissionexpect(trim($renderedMail->render()))->toContain('hidden-value-xyz');});++it('renders rich text field values as html in submission data', function () {+ $user = $this->actingAsUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace);++ $richTextField = [+ 'id' => 'rich-text-sample',+ 'name' => 'Rich Tex Sample',+ 'type' => 'rich_text',+ ];+ $form->properties = array_merge($form->properties, [$richTextField]);+ $form->update();++ $integrationData = $this->createFormIntegration('email', $form->id, [+ 'send_to' => $user->email,+ 'sender_name' => 'OpnForm',+ 'subject' => 'New form submission',+ 'email_content' => 'Hello there',+ 'include_submission_data' => true,+ ]);++ $richTextValue = '<p>Test <em>Sample </em><u>Underline </u><strong>Bold </strong><span style="color:rgb(230,0,0);">Colored</span></p><p><br /></p><p>Line break</p>';+ $formData = [+ $richTextField['id'] => $richTextValue,+ ];++ $event = new \App\Events\Forms\FormSubmitted($form, $formData);+ $mailable = new FormEmailNotification($event, $integrationData);+ $notifiable = new AnonymousNotifiable();+ $notifiable->route('mail', $user->email);++ $html = trim($mailable->toMail($notifiable)->render());++ expect($html)->toContain('<strong');+ expect($html)->toContain('Bold </strong>');+ expect($html)->toContain('<em');+ expect($html)->toContain('Sample </em>');+ expect($html)->not->toContain('<p>Test <em>Sample');+});