It’s not what the eForm event functions return that is important here. It’s what you do with the function parameters. The parameters are referenced meaning that if you change their value within the (event) function you are actually changing the value of the original variable. (See
http://au.php.net/manual/en/language.references.php)
When you create a function for the eFormObeforeFormParse event in the function declaration you place an ampersand before both parameters.
//<?php
function beforeFormParseFunction( &$fields, &$templates){ //or was it ( &$templates, &$fields)? you better check that!
//your code
}
//?>
In your case you want to make changes to the form template by adding options to a select field. The form template is stored in the function parameter $templates[’tpl’]. By setting a placeholder in your form template and replacing this with your db generated options in the $temapltes[’tpl’] variable you are actually changing the template outside the function.
//<?php
function beforeFormParseFunction( &$fields, &$templates){
global $modx;
//get options from database
$sql = "SELECT * FROM ".$modx->getFullTableName("site_tmplvar_contentvalues"). " WHERE tmplvarid = 11";
$rs = $modx->db->query($sql);
while( $row = $modx->getRow($rs) ) {
$options .= "\t<option value=\"".$row['value']."\">" . $row['value'] . "</option>\n"
}
//insert into template... assuming thet you have a [+dynamicOptions+] plcae holder :)
$templates['tpl'] = str_replace('[+dynamicOptions+]',$options,$templates['tpl']);
//all done,.. get out of here
return true;
//?>
That’s pretty much it. You should of course extend this with a bit of error checking and such. I’d create the whole select field from the function and first check if the query actually returned anything. If not don’t bother about a select field at all (or instead place a hidden field with a default value).
Anyway, have a read through the documentation and with this you should be getting along fine now.