Page 1 of 1

Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Thu Aug 27, 2009 12:19 pm
by kendo451
Formbuilder has some amazingly awesome flexibility.  I like the way I can pre-populate fields by including the value in the tag that calls the module.

I would like to be able to have a form where one of the fields is a pulldown list based on an array passed as a parameter in the module tag.

Something like this:

{user_defined_tag assign='options'} {* My user defined tag makes a list of options and puts them in $options as an array in the form key => value. *}

{cms_module module='FormBuilder' form='myform' fieldChoices_options=$options}

Anyone know of a way to do something like this with the current version of FormBuilder?

Re: Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Mon Nov 02, 2009 3:04 pm
by clj83
Hey,

Did you ever figure out a way to do this? I have just started reading around the forum to try and establish whether it is possible to populate a pulldown with values from an array in the Availability module. Don't know if it is possible but any advice would be great.

Cheers

Chris

Re: Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Mon Nov 02, 2009 3:40 pm
by kendo451
There is not a way to do this at present. You have to write your own module if you want to generate a dynamic pulldown list.

Re: Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Wed Nov 04, 2009 12:39 pm
by jack4ya
Have a look at CTL module maker.
http://dev.cmsmadesimple.org/project/files/581

You can make database contents, structures, and work it for dynamic dropdowns

Re: Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Tue Mar 02, 2010 12:23 am
by yelwor
I think I may have found a work around for this.  I'm using a query from a database to retrieve the values I needed for my pulldown list but I'm sure you'll be able to get the code working with an array.

1.  In FormBuilder create a field of Field Type: hidden and call it 'selectID'. On the Advanced Settings tab set the Field Alias to the same name e.g. "selectID".

2.  Create a user defined tag that creates your pulldown list dynamically.  Make sure that the OnChange event of the assigns the value of the selected item to your hidden field (selectID) that you created in step 1.  Below is a cutdown example of the code :-

Code: Select all

// get globals
global $gCms;
$smarty = &$gCms->GetSmarty();

// sql
$query_sql = "SELECT ID, Name 
                          FROM yourTable";
$query_data = mysql_query($query_sql);

// output
$htmlOutput  = '<select onchange="document.getElementById(\'selectID\').value=this.value;">';

// loop through recordset
while ($query_row = mysql_fetch_array($query_data)) {

     // output club values
     $htmlOutput .= '<option value="' . $query_row['Club_ID'] . '">' . $query_row['Club_Name'] . '</option>';
}

// output
$htmlOutput .= '</select>' ;

// return 
return $htmlOutput;
3.  In FormBuilder create another field of Field Type: User Defined Tag Call and set the User Defined Tag to the UDT you created in step 2.

You should now have a form that has a pulldown menu item generated by the UDT which when changed by the user updates the hidden field and posts the value with the rest of your form fields.

Good luck and let me know if it works for you!

Phil

Re: Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Tue Mar 02, 2010 7:37 am
by Peciura

Re: Generate a Dynamic Pull-Down List in Formbuilder?

Posted: Wed Mar 03, 2010 10:50 am
by yelwor
Thats the only problem with forums.  When you try to find an answer you can't.  Had I found your solution I would have saved myself hours!  Nevermind.  Two similar answers means twice the possibility for someone to find an answer to their problem!

Cheers

Phil