Online Chat
 Call Us: 
1-877-744-1221
Browse Submit a Ticket
 
Advanced Search
Tools
Rss Categories

"Switch" function

Author: Eileen Wilde Reference Number: AA-00171 Views: 9037 Last Updated: 08/12/2015 03:38 PM 0 Rating/ Voters

"Switch" function allows you to output a custom message depending on the user input. It simplifies some cases when you would use "If" conditions. It should be used if you have radio buttons, dropdown menus, or multiple lists and, on one hand, want to leave field values short and simple, and, on the other, hand want to output human-readable text depending on the user's choice. For example the "Switch" function can be used in email templates to allow a user to choose the department where email should be sent without storing the email on the form page.

Template:

{#sw(field_name, "field_values_separated_by_commas", "output_strings_separated_by_commas")#}

Example:

Please choose a department:
<label><input type="radio" name="sendto" value="support" checked>Support Dept.</label>
<label><input type="radio" name="sendto" value="sales">Sales Dept.</label>
<label><input type="radio" name="sendto" value="installations">Installations Dept.</label>

We use "Switch" function in one of the email templates:

To: {#sw(sendto, "sales,support,installations", "\"Sales\" <sales@web-site-scripts.com>,\"Support\" <support@web-site-scripts.com>,\"Installation\" <install@web-site-scripts.com>")#}

Let's say the user checks the "Sales Dept." radio button.

Result:

To:  "Sales" <sales@web-site-scripts.com>
Note:
If you want to pass a string with quotation marks inside, you need to shield them with backslashes like it shown in the examples above and below.
\"Sales\" <sales@web-site-scripts.com>

No spaces after commas

Please, avoid adding spaces after commas in the sw function.