Online Chat
 Call Us: 
Browse Submit a Ticket
Advanced Search
Rss Categories

"Switch" function

Author: Eileen Wilde Reference Number: AA-00171 Views: 5410 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.


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


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\" <>,\"Support\" <>,\"Installation\" <>")#}

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


To:  "Sales" <>
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\" <>

No spaces after commas

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