-
Notifications
You must be signed in to change notification settings - Fork 835
Forms: plain text email reply #44790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Forms: allow reply via email in plain text |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1112,10 +1112,11 @@ private static function get_raw_compiled_form_data( $feedback_id, $form = null ) | |
* | ||
* @param int $feedback_id - the feedback ID. | ||
* @param Contact_Form $form - the form. | ||
* @param bool $urlencoded - should the response be in urlencoded plain text, or HTML. | ||
* | ||
* @return array $lines | ||
*/ | ||
public static function get_compiled_form_for_email( $feedback_id, $form ) { | ||
public static function get_compiled_form_for_email( $feedback_id, $form, $urlencoded = false ) { | ||
$compiled_form = array(); | ||
$response = Feedback::get( $feedback_id ); | ||
|
||
|
@@ -1136,25 +1137,32 @@ public static function get_compiled_form_for_email( $feedback_id, $form ) { | |
* @param Contact_Form $form a copy of this object | ||
*/ | ||
$updated_compiled_form = apply_filters( 'jetpack_forms_response_email', $compiled_form, $feedback_id, $form ); | ||
|
||
if ( $updated_compiled_form !== $compiled_form ) { | ||
$compiled_form = $updated_compiled_form; | ||
} else { | ||
// add styling to the array | ||
// Add styling to the array | ||
foreach ( $compiled_form as $key => $value ) { | ||
$safe_display_label = self::escape_and_sanitize_field_label( $value['label'] ); | ||
$safe_display_label = self::maybe_add_colon_to_label( $safe_display_label ); | ||
$safe_display_value = self::escape_and_sanitize_field_value( $value['value'] ); | ||
$nl = '%0A'; // URLEncoded newlines | ||
|
||
if ( ! empty( $safe_display_label ) ) { | ||
$compiled_form[ $key ] = sprintf( | ||
'<p><strong>%1$s</strong><br /><span>%2$s</span></p>', | ||
self::maybe_add_colon_to_label( $safe_display_label ), | ||
$safe_display_value | ||
); | ||
$compiled_form[ $key ] = $urlencoded | ||
? rawurlencode( $safe_display_label ) . $nl . rawurlencode( $safe_display_value ) . $nl . $nl | ||
: sprintf( | ||
'<p><strong>%1$s</strong><br /><span>%2$s</span></p>', | ||
$safe_display_label, | ||
$safe_display_value | ||
); | ||
} else { | ||
$compiled_form[ $key ] = sprintf( | ||
'<p><span>%s</span></p>', | ||
$safe_display_value | ||
); | ||
$compiled_form[ $key ] = $urlencoded | ||
? rawurlencode( $safe_display_value ) . $nl . $nl | ||
: sprintf( | ||
'<p><span>%s</span></p>', | ||
$safe_display_value | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -2104,6 +2112,15 @@ public function process_submission() { | |
__( 'Mark as spam', 'jetpack-forms' ) | ||
); | ||
|
||
$message_urlencoded = self::get_compiled_form_for_email( $post_id, $this, true ); | ||
$reply_mailto_url = | ||
'mailto:' . | ||
rawurlencode( $reply_to_addr ) . | ||
'?subject=' . | ||
rawurlencode( 'Re: ' . $subject ) . | ||
'&body=' . | ||
implode( '', $message_urlencoded ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might need to check for URL length limits here. |
||
|
||
$footer = implode( | ||
'', | ||
/** | ||
|
@@ -2130,7 +2147,7 @@ public function process_submission() { | |
); | ||
|
||
$actions = sprintf( | ||
'<table class="button_block" border="0" cellpadding="0" cellspacing="0" role="presentation"> | ||
'<table class="button_block" border="0" cellpadding="0" cellspacing="8" role="presentation"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this HTML table gets moved to HTML template, and actions becomes more lightweight; either just link tags or URL+label. Now we're starting to split HTML layout in two different files which isn't great. |
||
<tr> | ||
<td class="pad" align="center"> | ||
<a rel="noopener" target="_blank" href="%1$s" data-tracks-link-desc=""> | ||
|
@@ -2143,10 +2160,23 @@ public function process_submission() { | |
<![endif]--> | ||
</a> | ||
</td> | ||
<td class="pad" align="center"> | ||
<a rel="noopener" target="_blank" href="%3$s" data-tracks-link-desc=""> | ||
<!--[if mso]> | ||
<i style="mso-text-raise: 30pt;"> </i> | ||
<![endif]--> | ||
<span>%4$s</span> | ||
<!--[if mso]> | ||
<i> </i> | ||
<![endif]--> | ||
</a> | ||
</td> | ||
</tr> | ||
</table>', | ||
esc_url( $dashboard_url ), | ||
__( 'View in dashboard', 'jetpack-forms' ) | ||
__( 'View in dashboard', 'jetpack-forms' ), | ||
esc_url( $reply_mailto_url ), | ||
__( 'Reply via email', 'jetpack-forms' ) | ||
); | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: enhancement | ||
|
||
Forms: allow reply via email in plain text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this function returning "HTML" or "urlencoded array" is great and should not land in this format the PR, but it served as a quick demo.
We should be able to get "plain text" and "HTML" versions of form submissions, which then carries it all the way down to how file upload fields, multi line text fields etc get rendered.
Plain text can then be used to render plain text version of the full email as well, for those clients that instruct not to get HTML versions.
Then we can use plain text in emails and just wrap it in
urlencode()
.