Is it possible to automatically populate a select list from a database table?

Yes, this is possible.

You will need to write a 'Before Form Piece' - a small PHP script that gets executed before the form is loaded. Within it, you can specify a SQL statement, query the database and put the results into your form.

The values of a select-list have the form 0;foo;bar so all you need to do is to dynamically build a string with the desired values and then provide it to the function mentioned below. Here is a sample to fetch the usernames from your DB and populate them to a select list.

All you need is a select list named select1 (with empty list values) and this Before Form Piece:

 

$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object
 
//Create your own query here
$db->setQuery('Select username From #__users '); 
 
$result = $db->loadColumn(); //load the result from the query
$test = "";
for ($i = 0; $i < count($result); $i++)
{
     $test .= "0;".$result[$i].";".$result[$i]."\n";
}

function ff_setSelectList($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList

ff_setSelectList('select1', $test);

 

To use it, Go to your form's properties and then to the 'Advanced' tab > More options. In the popup window that opens, select the tab 'Form pieces.' In the BEFORE FORM section, choose the 'Custom' radio button. Paste your script in there and then make changes as needed.

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!