dynamic dropdown based on php variable

marklandry 20 Mar, 2013
Hi,
I need a dropdown that has numeric values that are less than a php variable

So, php var is something like $max=8;

I need dropdown options "8,7,6," etc.

I can do it in custom html mode but would like to know if there's a different, cleaner way to do it?

Thanx for your help

Mark
GreyHead 20 Mar, 2013
Hi Mark,

You can do this with a Custom Code action to build the options array and the Dynamic Data tab of a Select Drop-Down element. Here's a generalised example of the Custom Code:
<?php
$form->data['opt_min'] = 3;
$form->data['opt_max'] = 10;
$form->data['options'] = array();
$form->data['options'][] = array('value' => '', 'text' => 'Please choose');
for ( $i = $form->data['opt_min']; $i <= $form->data['opt_max']; $i++ ) {
  $form->data['options'][] = array ('value' => $i, 'text' => $i);
}
?>

And the corresponding settings on the Dynamic Data tab of the element are:
Enable : Yes
Data Path: options
Value Key: value
Text Key: text
You can change these settings as long as they match up with the entries in the $form->data array created in the Custom Code action.

Bob
This topic is locked and no more replies can be posted.