Generate a Dynamic Pull-Down List in Formbuilder?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
kendo451

Generate a Dynamic Pull-Down List in Formbuilder?

Post 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?
clj83
Forum Members
Forum Members
Posts: 195
Joined: Tue Jul 07, 2009 4:09 pm

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

Post 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
kendo451

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

Post 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.
jack4ya
Power Poster
Power Poster
Posts: 294
Joined: Thu Oct 19, 2006 10:07 am

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

Post 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
yelwor
Forum Members
Forum Members
Posts: 33
Joined: Thu Jan 10, 2008 9:37 pm

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

Post 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
yelwor
Forum Members
Forum Members
Posts: 33
Joined: Thu Jan 10, 2008 9:37 pm

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

Post 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
Locked

Return to “Modules/Add-Ons”