Dynamic options for dropdowns and multi selection fields

Complete Guide: How to Setup Dynamic Options in ChronoForms v8 & v7

Overview

Learn how to configure dynamic options for dropdown and multi-selection fields in ChronoForms. The guide covers preparing your options array using a PHP action for static/complex data or a Read Data action for database-driven options. It explains setting the Data Source, Option value path, and Option text, including updates for v8.0.47 to handle single-dimension arrays.

Here is how to setup the Dynamic Options behavior for the dropdown fields and multi selection fields in ChronoForms v8, the same setup can be used for Chronoforms v7

Start by preparing your options array, your can do this using:

  1. PHP action if your have a static or complex source of data
  2. Read Data action action if your options are coming from the database directly

PHP action settings

Dynamic options for dropdowns and multi selection fields image 1

The PHP actions will return an array with options values and texts

Next, enable the Dynamic Options behavior in your dropdown and set the Data Source as {var:php25}, which in this case is the returned value from PHP action named "php25", the action we have just created

We will also need to set the Option value path to: {row:value} and the Option value text to {row:text} as this is the path for the values and texts in our array:

Dynamic options for dropdowns and multi selection fields image 2

You may add any default options to the Options box, those will appear before the dynamic options.

Read Data settings

Dynamic options for dropdowns and multi selection fields image 3

And your dropdown Dynamic Options will change accordingly:

Dynamic options for dropdowns and multi selection fields image 4

  1. We use the results of the action named "read_users" as the Data Source
  2. We use the row's id value for the option value, each row coming from the users table will have an "id" column value
  3. We use the row's username value for the option text, each row coming from the users table will have a "username" column value

v8.0.47 Update

if you have ChronoForms v8.0.47 or later, you may also use {row:key} and {row:value} if your values are a single dimension array, coming from a JSON array in the database for example:

Dynamic options for dropdowns and multi selection fields image 5

in this case {row:key} will hold the numeric value index, and {row:value} will hold the value itself

You may also like:

Comments:

You need to login to be able to post a comment.