preignition/program-user-docs
accessiblesurveys
  • TRAINING COURSE
    • Introduction
    • Session 1- Creating a new survey
    • Session 2- Adding accessibility options to a Form
    • Session 3- Translating a Form into different languages
    • Session 4- Sharing your survey using the Survey Editor
    • Session 5- Analysing your survey responses and exporting your survey data
  • TUTORIALS
    • Introduction to creating a new survey
    • Introduction editing a form
    • Introduction to testing a form
    • Introduction to publishing a form
    • Introduction to Easy Read
    • Introduction to Sign Language
    • Introduction to form logic
    • Introduction to the Customer Portal
  • GUIDANCE NOTES
    • Survey App
      • Creating a new survey
      • Form Editor
        • Structuring a form
        • Adding questions to a form
          • Text based questions
          • Choice based questions
          • Rating, Slider, Order and Range questions
          • Media based questions
          • Introduction to free text fields
        • Testing a form
        • Publishing a form
        • Introduction to form logic
        • Advanced form logic
        • Using tooltips
        • Using Markdown
        • Adding an accessibility menu
        • Form Behaviour
        • Image Library
        • Easy Read
        • Sign Language
        • Translate forms
        • Using import/ export to translate forms
        • Access rights for forms
        • Sharing options across multiple questions
      • Survey Editor
        • Editing a survey
        • Distributing your survey
        • Survey respondent accounts
        • Redirection after completing survey
        • Language settings for surveys
        • Creating alias survey links
        • Survey batches
        • Presenting surveys
        • Survey access rights
        • Survey terms- advanced
        • Publishing surveys
      • Analytics
        • Introduction to survey analytics
        • Exporting Survey Data
    • Customer Portal
      • Portal
        • Profile
        • Subscription
      • Team
      • My Profile
      • Users
      • Using labels
  • FAQ
    • Data privacy and security
      • Why and how do we collect data?
      • How do we protect data?
      • What is GDPR?
      • What rights do individuals have under GDPR?
      • What obligations do controllers have under GDPR?
      • What obligations do processors have under GDPR?
      • Where is data stored?
      • How can I ensure that my surveys GDPR compliant?
      • How to Write GDPR-proof Privacy Policy for your Surveys
    • What is the best image size, ratio and format?
    • How to use free text
      • Convenient Class for Accessible Surveys Free Text Field
      • CSS tokens available in Markdown Free Text
      • Web-components available in Markdown Free Text
      • Accessibility Modes
    • FAQ about the Form Editor
      • How do I resolve warnings when publishing a form?
      • How can I get feedback about my survey?
    • Guide to producing Accessible Surveys
      • Producing your survey in Plain Language or Easy to Read
      • Producing your survey in sign languages
    • FAQ about survey data and analytics
      • How do I ensure that the data in my CSV file is properly formatted?
  • Release Notes
    • Form Builder
      • import/export
      • Section Container
    • Process Builder
    • Reporting
    • Survey
  • API
    • survey
    • member
Powered by GitBook
On this page
  • What is a logical expression?
  • Worked example
  • How to write a logical expression?
  • Testing a logical expression
  • How to hide a question initially
  • What logic options are available?
  • Tips for applying form logic
  1. GUIDANCE NOTES
  2. Survey App
  3. Form Editor

Introduction to form logic

This page provides an introduction to form logic.

PreviousPublishing a formNextAdvanced form logic

Last updated 1 year ago

Adding logic to a form enables you to customize how your form behaves when respondents are filling it in

What is a logical expression?

Logical expressions are mathematical expressions which return a result of either "True" or "False".

A defined action is then applied depending upon the result.

For Pages and Sections, form logic is used to control whether a page or section is visible or hidden.

For Questions, 'required', 'invalid' and 'read-only' attributes can be also be applied in addition to the 'hidden' attribute'

Worked example

For example, you may be interested in whether your respondents like fruit or not. If they do, you would like to ask a follow up question to understand the sort of fruit they like.

It doesn't make sense to ask the follow up question if the answer to the first question is 'no'. Logic allows you to hide the follow up question.

How to write a logical expression?

To access the logic function you must switch on the 'Advanced' toggle at the top of the screen. A 'logic mode' icon will appear in the bottom right hand corner

Below is an example of the logic feild for the question we outlined above about fruit

Always select the option 'Lock this question while editing logic'.

Logic has been added to the follow up question 'what sort of fruit do you like?' so that it is displayed or hidden depending on the answer to the previous question 'Do you like fruit?'

  • The question 'Do you like fruit?' has been dragged from the tree grid in the left hand column into the expression feild along with the answer 'No'

  • An equals sign (==) has been entered to set up a mathmatical expression. ie is the answer to the question 'Do you like fruit?' 'No'?

  • If the respondent then answers 'No', the expression result will be 'true' and the follow up question 'what sort of fruit do you like?' will be hidden.

  • In all other scenarios, such as respondent not answering the question 'Do you like fruit' or answering 'Yes', the expression result will be 'false' and the follow up question will be displayed

Testing a logical expression

It is possible to test a logical expression by toggling on the button 'test expression' as shown in the example above.

This brings up all the questions that have been refered to in the expression.

Try answering the questions and check whether the expression result gives the desired outcome.

Form logic is extremely powerful and adds focus and dynamism to your forms. However it takes some pratice. We suggest starting with simple expressions and testing regularly

How to hide a question initially

Often you will want a question to be hidden initially and for it only to appear based on an answer to a previous question

The question 'what sort of fruit do you like?' is a good example.

With the logical expresssion written above, the follow up question is visible initially and is only hidden if a respondent answers 'No' to the the question 'Do you like fruit?'

It would be preferable if the question is hidden initially and is only displayed if a respondent answers 'Yes' to the question 'Do you like fruit?'

Use ! to invert the expression and hide a question initially

  • Use != for Not Equal.

  • In the example above, the expression now asks whether the question 'Do you like fruit?' does Not equal 'yes'

  • If the question 'Do you like fruit' is not answered or the answer is 'No' the expression result will be 'True' and the follow up question will be hidden

  • Only if the answer is 'Yes' will the expression result be 'False' and the follow up question will be displayed

What logic options are available?

A wide range of logic options are available. The most commonly used are as follows:

Operator
Symbol

Equal

==

Not equal

!=

Greater than

>

Greater than or equal

>=

Less than

<

Less than or equal

<=

Element in array or string

in

Logical AND

&&

logical OR

||

Negate

!

Tips for applying form logic

  • Apply the logic to the resource (Page, Section or question) which you want the action to be applied to

  • Apply the logic as high up in the form structure as possible. If you have a number of Questions which you want to apply the same logic expression to, first add the questions to a Section, and apply the logic to the section.

  • When writting complex logic, it is easier to create an expression that is true and then invert it if necessary. Create the true expesssion first and then invert the expression using (!(expression).

  • Always select the option 'Lock this question while editing logic' and unselect this option when you have finished writing the logical expression.

Short video showing how to test a logical expression
Example of a question where logic can help
Screenshot showing the advanced toggle being activated. The 'logic mode' icon appears in the bottom right of the screen. The 'lock this question while editing logic' toggle has been activated.
Screenshot showing how to hide a question initially using !=