Convert Forms provides an IF shortcode that allows you to perform conditional logic based on user input and global conditions across various sections, including Success Message, Emails using Tasks, HTML Fields, or even in the PDF Form Submission.
The syntax is the following:
{if condition1 = value1 AND condition2 = value2}
content here
{else}
alternative content here
{/if}
To delve deeper into the details of syntax, explore the various comparison operators, build-in conditions, and functions, visit Using the Conditional Content Shortcode in Tassos Extensions. If you are familiar with the syntax, you can proceed below to learn more about incorporating it effectively with Convert Forms.
TABLE OF CONTENTS
- Requirements
- Where Can I Use It?
- Conditional Content Based on User Input
- Conditional Content Based on Submission State
- Conditional Content Based on Global Conditions
Requirements
You will need Convert Forms Pro 4.3.0+ to use the conditional content shortcode.
Where Can I Use It?
The shortcode is versatile and can be employed almost anywhere you can write text within the Convert Forms builder. It seamlessly integrates into key areas, including:
- Success Message
- Email Message using Tasks
Note: The deprecated "Behavior > Email Notifications" do not support Conditional Content Shortcodes. - PDF Form Submission
- HTML Fields
- Form Footer
- Custom CSS
- Custom Code
Conditional Content Based on User Input
The shortcode allows you to perform conditional logic based on the user input after the form submission. To do so, use the following syntax:
{if field.FIELDNAME = value} content here {/if}
Where FIELDNAME is the field name, you would like to compare its value.
Let’s see some practical use cases:
Show content if a field equals a certain value
The most common scenario is where we want to check whether a field equals a certain value. Let’s say the field we want to check is named “name”. To do so, use the Equals operator as in the example below:
{if field.name = John Doe} Your content here {/if}
Show content if a field contains a certain text
Let’s say your form includes an email field where you would like to check whether the user entered a Gmail address. To determine whether a field value contains another text, use the Contains operator, as in the example below:
{if field.email contains gmail.com} Your content here {/if]
Show content if a number field is less than another number
Imagine your form includes a number field named “year” posing the question "Year of Birth". You want to display the text “Not old enough” when the user does not meet age requirements, specifically when the user input is less than 2005. Achieve this by utilizing the following shortcode:
{if field.year < 2005} Not old enough {/if}
Show content if a certain dropdown or radio button option was selected
Imagine your form incorporates a dropdown or radio buttons field named "math" posing the question "What's 5+5?" with the choices: 5, 10, and 15. If the user selects the accurate response, you want to present the message "Your answer is correct". Achieve this by utilizing the following shortcode:
{if field.math = 10} Your answer is correct {/if}
Show content if a field is empty
Let’s say your form includes an optional field named “age” and you want to present a specific message when the field is blank. To determine whether a field is empty, use the Empty operator as follows:
{if field.age empty} Your content here {/if}
This can also be written as:
{if !field.age} Your content here {/if}
Show content if a date field corresponds to the current day
Let’s say there’s a date field in your form named “checkIn” and you would like to display a certain content when the user selects a date corresponding to the current day. To do so, utilize the today() built-in function as in the example below:
{if field.checkIn = today()} Your content here {/if}
Show content based on how many files the user uploaded
Let’s say your form includes a file upload field named “uploads”, and you would like to create conditional logic based on how many files the user has uploaded, and specifically if the user uploads more than 3 files, display a certain text.
To do so, you will need to utilize the count() built-in function as follows:
{if count(field.uploads) > 3} Your content here {/if}
Conditional Content Based on Submission State
The shortcode allows you to perform conditional logic based on information regarding the submission. To do so, use the following syntax:
{if submission.CONDITION = value} Your content here {/if}
Where CONDITION can be any of the following:
Condition | Return Format | Expected Value |
---|---|---|
id | Numeric | A number representing the unique ID of the submission |
created | Datetime | A date representing the date the submission was created. |
modified | Datetime | A date representing the date the submission was last modified. |
form_id | Numeric | A number representing the ID of the form associated with the submission |
user_id | Numeric | The ID of the Joomla User account submitted the form.
If the user is not logged in, it will return 0. |
state | Numeric |
A number representing the submission status, and it can be any of the following:
|
count | Numeric | A number representing the total number of submissions the form has received. |
Show content based on the submission date
In the scenario where you would like to display content based on the submission date, use the submission.date as follows:
{if submission.date > 10-20-2024} Your content here {/if}
Show content based on the submission count
You can also compare based on a form's number of submissions. To do so, use the submission.count condition as follows:
{if submission.count <= 1000} Your content here {/if}
Show content based on the submission state
You can also compare based on the state of the submission. For instance, you may need to display the text “Confirmed” and “Pending” respectively. To do so, use the submission.state condition as follows:
{if submission.state = 1}
Confirmed
{else}
Pending
{/if}
Conditional Content Based on Global Conditions
With the Convert Forms Conditional Content Shortcode, you can restrict or grant access to content parts based on various conditions such as Device, User Group, Date, URL, Language, and more.
To learn more details about the available conditions, visit the Conditions section.