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.