Blog Sections Open

Sending HTML Cart Emails with eForm

eForm can be used for more than simple contact forms. One common legacy pattern was sending an order summary email with an HTML table of cart items. Typical eForm Call [!eForm? &formid=`cart-form` &tpl=`cart-form-tpl` &r

eForm can be used for more than simple contact forms. One common legacy pattern was sending an order summary email with an HTML table of cart items.

Typical eForm Call

[!eForm?
 &formid=`cart-form`
 &tpl=`cart-form-tpl`
 &report=`cart-report-tpl`
 &allowhtml=`1`
 &sendAsHtml=`1`
!]

Cart Data Builder

$count = $_POST['itemCount'];
$str = '<table>';
for ($i = 1; $i <= $count; $i++) {
    $str .= '<tr><td>' . $_POST['item_options_' . $i] . '</td>'
          . '<td>' . $_POST['item_name_' . $i] . '</td>'
          . '<td>' . $_POST['item_quantity_' . $i] . '</td></tr>';
}
$str .= '</table>';
return $str;

The key is to generate the structured cart block separately, then inject it into the report template as one placeholder. That keeps the mail template readable and the item assembly logic isolated.

Newer post

Using splitPagination to Reshape Ditto Page Links

How splitPagination can restyle and restructure standard Ditto pagination without rewriting the whole listing layer.

Older post

Making Wayfinder Dropdown Templates Work with startId=0

How to reason about parentRowTpl, parentClass, and dropdown markup when Wayfinder builds a menu from the root of the site tree.