This article outlines some of the variables that are helpful when developing email content and PDF templates.
Adding Field Values
The #field(id)
variable is used to add field values to your email templates. Although not necessary, you can also use #field_label(id)
to dynamically add labels for each field value.
Example
<p><strong>#field_label(1)</strong><br />#field(1)</p> <p><strong>#field_label(2)</strong><br />#field(2)</p>
In this example #field_label(1)
is replaced with the label of the field with ID 1, and the value of the field in inserted with #field(1)
.
Conditionally Showing Field Values
Sometimes you may only wish to show a field value if it contains a value. To do this, you can use the #if(condition)
and #endif
variables.
Example
#if(#field(1)) <p><strong>#field_label(1)</strong><br />#field(1)</p> #endif #if(#field(2)) <p><strong>#field_label(2)</strong><br />#field(2)</p> #endif
In this example, WS Form checks to see if the field with ID 1 has content. If it does, it shows the content between the #if(#field(1))
and #endif
variables. This functionality is then repeated for the field with ID 2.
Repeatable Sections
If a field is in a repeatable section, #field(id)
will return the field values for each row in a comma separated list, for example:
Red,Green,Blue
You can also output custom HTML for each row by using the #section_rows_start(id)
and #section_rows_end
variables.
Example
<table> <thead> <tr> <th width="20">#</th> <th>#field_label(1)</th> <th>#field_label(2)</th> </tr> </thead> <tbody> #section_rows_start(10) <tr> <th>#section_row_number</th> <td>#field(1)</td> <td>#field(2)</td> </tr> #section_rows_end </tbody> </table>
In this example, the HTML between #section_rows_start(10)
and #section_rows_end
is repeated for each row added to the repeatable section having ID 10. The HTML can contain any of the field values contained within that repeatable section.
The #section_row_number
variable adds the number of the corresponding row. An example of the output from this HTML is shown below.
You can combine this with the #if(condition)
and #endif
variables too.
Variables
Some of of the commonly used WS Form variable that are used in email templates are shown below:
Name / Variable | Additional Information |
---|---|
Character set#email_charset | Returns the email character set. For more information about this variable, click here. |
Content type#email_content_type | Returns the email content type. For more information about this variable, click here. |
E-Commerce Values#email_ecommerce | Returns a list of the e-commerce transaction details such as total, transaction ID and status fields. For more information about this variable, click here. |
Logo#email_logo | Returns the email logo specified in WS Form Settings > Variables. For more information about this variable, click here. |
Subject#email_subject | Returns the email subject line. For more information about this variable, click here. |
Submitted Fields#email_submission(tab_labels, section_labels, field_labels, blank_fields, static_fields) | Returns a list of the fields captured during a submission. You can either use: #email_submission or provide additional parameters to toggle tab labels, section labels, blank fields and static fields (such as text or HTML areas of your form). Specify 'true' or 'false' for each parameter, for example: #email_submission(true, true, false, true, true) For more information about this variable, click here. |
Tracking data#email_tracking | Returns a list of all the enabled tracking data that was captured when the form was submitted. For more information about this variable, click here. |
Field
Name / Variable | Additional Information |
---|---|
Field Value#field(field_id, "delimiter", "column") | Use this variable to insert the value of a field on your form. For example: #field(123) where '123' is the field ID shown in the layout editor. If delimiter specified, fields with multiple values (e.g. checkboxes) will be separated by the specified delimiter. If column is specified it will return the value found in that data grid column. The value of column can be the column label or index (starting with 0). |
Count the Number of Characters in a Field#field_count_char(field_id, "regex_filter") | Use this variable to insert the number of characters in a field on your form. For example: #calc(#field_count_char(123)) where '123' is the field ID shown in the layout editor. Optionally specify a JavaScript regex to filter the characters included in the calculation. For example: #calc(#field_count_char(123, "/[^0-9a-z]/gi")) . |
Count the Number of Words in a Field#field_count_word(field_id, "regex_filter") | Use this variable to insert the number of words in a field on your form. For example: #calc(#field_count_word(123)) where '123' is the field ID shown in the layout editor. Optionally specify a JavaScript regex to filter the characters included in the calculation. |
Field Date Formatted#field_date_format(field_id, "format") | Return a field formatted according to the PHP date function. |
Field Date Adjusted by Offset in Seconds#field_date_offset(field_id, seconds_offset, "format") | Return a date adjusted by an offset in seconds. |
Field Value as Floating Point Number#field_float(field_id) | Use this variable to insert the value of a field on your form as a floating point number. For example: #field(123) where '123' is the field ID shown in the layout editor. This can be used to convert prices to floating point numbers. An example output might be: 123.45 |
Field Label#field_label(field_id) | Returns the field label by ID. |
Field ID with Max Value#field_max_id(field_id) | Use this variable to return the ID of the field containing highest value. For example: #calc(#field_max_id(5, 6, 7, 8)) . This would check fields IDs 5, 6, 7, and 8 and return the field ID containing the highest value. |
Field Label with Max Value#field_max_label(field_id) | Use this variable to return the label of the field containing highest value. For example: #calc(#field_max_id(5, 6, 7, 8)) . This would check fields IDs 5, 6, 7, and 8 and return the field label containing the highest value. |
Maximum Value of Fields#field_max_value(field_id) | Use this variable to return the highest value for the supplied field IDs. For example: #calc(#field_max_value(5, 6, 7, 8)) . This would check fields IDs 5, 6, 7, and 8 and return the highest value contained within those fields. |
Field ID with Min Value#field_min_id(field_id) | Use this variable to return the ID of the field containing lowest value. For example: #calc(#field_min_id(5, 6, 7, 8)) . This would check fields IDs 5, 6, 7, and 8 and return the field ID containing the lowest value. |
Field Label with Min Value#field_min_label(field_id) | Use this variable to return the label of the field containing lowest value. For example: #calc(#field_min_id(5, 6, 7, 8)) . This would check fields IDs 5, 6, 7, and 8 and return the field label containing the lowest value. |
Minimum Value of Fields#field_min_value(field_id) | Use this variable to return the minimum value for the supplied field IDs. For example: #calc(#field_min_value(5, 6, 7, 8)) . This would check fields IDs 5, 6, 7, and 8 and return the lowest value contained within those fields. |
Section
Name / Variable | Additional Information |
---|---|
Section Label#section_label("section_id") | Returns the section label. For more information about this variable, click here. |
Section Row Count#section_row_count("section_id") | Returns the total number of rows in a repeatable section. For more information about this variable, click here. |
Section Row Index#section_row_index | Returns the row index in a repeatable section. For more information about this variable, click here. |
Section Row Number#section_row_number | Returns the row number in a repeatable section. For more information about this variable, click here. |
Tab
Name / Variable | Additional Information |
---|---|
Tab Label#tab_label(tab_id) | Returns the tab label by ID. For more information about this variable, click here. |
Setting Up Send Email Actions to Use Custom HTML
We recommend setting the ‘Message Editor’ to ‘HTML’ in the ‘Send Email‘ action. This will ensure any custom HTML you enter is not adjusted by the WordPress visual editor.
Removing the Email Wrapper Template
WS Form wraps messages in a header and footer. This provides a simple email template that restricts the width of the email to 580px contained within a gray panel and adds necessary HTML tags around your message.
If you would like to remove this template and instead write your email template from <html>
to </html>
you can uncheck the Wrap Message in Header setting.