Forums

PHP - Dynamic Options Dropdown

nbradshaw45 27 Aug, 2021
I am new to Chronoforms and struggling to understand how to populate a dropdown with an array from a mysql query using the php action.

For now - I am just trying to understand the basics - so let's start with this:

PHP ACTION (php_11)
$cars = array("Volvo", "BMW", "Toyota");$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");return $age;

Dropdown Field:
Set with Dynamic Options. I am using {var:php_11} .

I am not getting anything to show up. Can I please get some assistance? I have also tried $cars - nothing is populating the dropdown.
GreyHead 22 Sep, 2021
Hi nbradshaw45,

There is a Tutorial video here that appears to answer your question. Please check it and see if it does.

You can see other video tutorials by checking the ? icon in the form toolbar.

Bob
nbradshaw45 23 Sep, 2021
Bob - thanks for the reply - however, the video is for the read_data action. I am needing the php_data action to work.
flashfs 03 Dec, 2021
After trying many things, I have this situation that could work for you.

On php action
I have an array like: array(array("value" => "value1", "text" => "text1"), array("value" => "value2", "text" => "text2))

On dropdown dynamic datasource
{var:php_11}
On options text and value
{var:value}
{var:text}
You need to login to be able to post a reply.