Skip to content

Instantly share code, notes, and snippets.

@ThemeCatcher
Last active August 29, 2023 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThemeCatcher/6c229e451c5227903533b0e0ce9b9990 to your computer and use it in GitHub Desktop.
Save ThemeCatcher/6c229e451c5227903533b0e0ce9b9990 to your computer and use it in GitHub Desktop.
Converts the form data in emails to a two column layout. Click Download ZIP and install it like a regular WP plugin, applies to all forms once active.
<?php
/*
* Plugin Name: Quform Two Column Email Layout
* Plugin URI: http://www.quform.com
* Description: Converts the form data in emails to a two column layout.
* Version: 1.0.0
* Author: ThemeCatcher
* Author URI: http://www.themecatcher.net
*/
add_filter('quform_all_form_data_html', function ($content, Quform_Form $form, $showEmptyFields) {
$newline = "\r\n";
$content = '<table width="100%" cellpadding="10" cellspacing="0" border="0" style="table-layout: fixed; background: #ffffff; border-spacing: 0; border-collapse: separate; border-bottom: 1px solid #d4d4d4; box-shadow: 0 2px 7px 0 rgba(0, 0, 0, 0.07);">' . $newline;
$content .= '<colgroup><col style="width:300px;"></colgroup>';
foreach ($form->getRecursiveIterator(RecursiveIteratorIterator::SELF_FIRST) as $element) {
if ( ! $element instanceof Quform_Element_Field && ! $element instanceof Quform_Element_Container && ! $element instanceof Quform_Element_Html) {
continue;
}
// Skip hidden elements
if ($element->isHidden()) {
continue;
}
// Skip empty elements
if ($element->isEmpty() && ! $showEmptyFields) {
continue;
}
if ($element instanceof Quform_Element_Html) {
if ($element->config('showInEmail')) {
$content .= '<tr><td colspan="2" valign="top" style="padding: 10px; font-family: Helvetica, Arial, sans-serif; font-size: 16px; color: #282828; line-height: 130%; border: 1px solid #d4d4d4; border-bottom: 0; word-wrap: break-word;">' . $element->getContent() . '</td></tr>' . $newline;
}
} else if ($element instanceof Quform_Element_Page) {
if ($element->config('showLabelInEmail') && Quform::isNonEmptyString($element->config('label'))) {
$content .= '<tr><td colspan="2" valign="top" style="padding: 10px; font-family: Helvetica, Arial, sans-serif; font-size: 22px; font-weight: bold; background-color: #c73412; color: #ffffff; border-bottom: 1px solid #e14e2c; word-wrap: break-word;">' . esc_html($element->config('label')) . '</td></tr>' . $newline;
}
} else if ($element instanceof Quform_Element_Group) {
if ($element->config('showLabelInEmail') && Quform::isNonEmptyString($element->config('label'))) {
$content .= '<tr><td colspan="2" valign="top" style="padding: 10px; font-family: Helvetica, Arial, sans-serif; font-size: 17px; background-color: #c73412; color: #ffffff; word-wrap: break-word;">' . esc_html($element->config('label')) . '</td></tr>' . $newline;
}
} else if ($element instanceof Quform_Element_Field) {
if ($element->config('showInEmail')) {
$content .= '<tr><td bgcolor="#efefef" valign="top" style="padding: 10px; font-family: Helvetica, Arial, sans-serif; font-size: 15px; font-weight: bold; color: #282828; border: 1px solid #d4d4d4; border-bottom: 0; word-wrap: break-word;">' . esc_html($element->getAdminLabel()) . '</td>' . $newline;
$content .= '<td bgcolor="#fcfcfc" valign="top" style="padding: 10px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #282828; line-height: 130%; border: 1px solid #d4d4d4; border-bottom-color: #fff; border-left-color: transparent; word-wrap: break-word;">' . $element->getValueHtml() . '</td></tr>' . $newline;
}
}
}
$content .= '</table>' . $newline;
return $content;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment