Skip to content

Commit 516d24b

Browse files
authored
Forms: Better handle custom submission message formatting (#45487)
* revert margin for custom message paragraphs * changelog * respect multiple empty lines * fix css where clause * prefix css class and add pretty text wrap
1 parent 2bff57e commit 516d24b

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Forms: Better handle custom submission message formatting

projects/packages/forms/src/contact-form/class-contact-form.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,8 @@ private static function render_ajax_success_wrapper( $form, $submission_success
991991
"</h4>\n\n";
992992

993993
if ( 'message' === $form->get_attribute( 'customThankyou' ) ) {
994-
$raw_message = wpautop( $form->get_attribute( 'customThankyouMessage' ) );
994+
$raw_message = $form->get_attribute( 'customThankyouMessage' );
995+
995996
// Add more allowed HTML elements for file download links
996997
$allowed_html = array(
997998
'br' => array(),
@@ -1007,7 +1008,10 @@ private static function render_ajax_success_wrapper( $form, $submission_success
10071008
),
10081009
);
10091010

1010-
$html .= wp_kses( $raw_message, $allowed_html );
1011+
$message = wp_kses( $raw_message, $allowed_html );
1012+
$message = '<div class="jetpack_forms_contact-form-custom-success-message">' . $message . '</div>';
1013+
1014+
$html .= $message;
10111015
} elseif ( ! $disable_summary ) {
10121016
$html .= '<template data-wp-each--submission="context.formattedSubmissionData">
10131017
<div>
@@ -1057,7 +1061,8 @@ public static function success_message( $feedback_id, $form ) {
10571061
$disable_summary = 'noSummary' === $form->get_attribute( 'customThankyou' );
10581062

10591063
if ( 'message' === $form->get_attribute( 'customThankyou' ) ) {
1060-
$raw_message = wpautop( $form->get_attribute( 'customThankyouMessage' ) );
1064+
$raw_message = $form->get_attribute( 'customThankyouMessage' );
1065+
10611066
// Add more allowed HTML elements for file download links
10621067
$allowed_html = array(
10631068
'br' => array(),
@@ -1072,7 +1077,9 @@ public static function success_message( $feedback_id, $form ) {
10721077
'style' => array(),
10731078
),
10741079
);
1075-
$message = wp_kses( $raw_message, $allowed_html );
1080+
1081+
$message = wp_kses( $raw_message, $allowed_html );
1082+
$message = '<div class="jetpack_forms_contact-form-custom-success-message">' . $message . '</div>';
10761083
} elseif ( ! $disable_summary ) {
10771084
$compiled_form = self::get_compiled_form( $feedback_id );
10781085
$message = '<p>' . implode( '</p><p>', $compiled_form ) . '</p>';

projects/packages/forms/src/contact-form/css/grunion.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ that needs to mimic the input element styles */
225225
word-wrap: break-word;
226226
}
227227

228+
.contact-form-submission :where(.jetpack_forms_contact-form-custom-success-message) p {
229+
margin: revert;
230+
}
231+
232+
.contact-form-submission :where(.jetpack_forms_contact-form-custom-success-message) {
233+
white-space: pre-wrap;
234+
text-wrap: pretty;
235+
}
236+
228237
.contact-form-submission h4 {
229238
margin-top: 32px;
230239
margin-bottom: 32px;

0 commit comments

Comments
 (0)