Login
Please enter your email address and password to login to the help desk.
(leave blank if you forgot your password)
   Save my login information
 

IMPORTANT NOTE:

DUE TO STUCTURAL CHANGES, THE TICKET SYSTEM IS NO LONGER ACCEPTING TICKETS. IF YOU ARE A PAYING SUBSCRIBER, PLEASE LOGIN TO THE CROSSTEC SITE AND USE THE CLUB FORUMS. THE CLUB FORUMS CATEGORY WILL APPEAR RIGHT AFTER LOGIN IF YOU ARE A PAYING CUSTOMER:

>>> Click here to access the forums <<<

We will close the knowledgebase soon as well and move its contents into a new knowledgebase system.

Knowledge Base » BreezingForms » FAQ
Auto-Populate a Select List from Database Table
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 Before Form Piece:


$this->execPieceByName('ff_InitLib');

$test = "";

for ($i = 0; $i < 10; $i++) {
   $test .= "0;Product {$i};value{$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. (You will probably want to replace the static 'for' loop with your SQL query.)

 

Was this helpful? Yes No Print Pdf