Thanks for your help once again, it all works as I hoped it would TobyL...
For anyone else looking for a solution, this was the code for the function which is contained within a snippet called [!SelectBoxParser!]
<?php
function populate(&$fields, &$templates){
$names = array(
"General Information" => 1,
"Something more personal" => 2,
"Something very personal" => 3,
"Send spam here" => 4,
"Any other gumpf" => 5,
);
global $modx; // Access to DocumentParser
$evt =& $modx->event; // The Snippet call event (not eFormOnBeforeFormParse event)
// Replicate $isPostBack variable
$validFormId = ($evt->params['formid'] == $_POST['formid']);
$isPostBack = ($validFormId && count($_POST) > 0);
// (bool)true if the form is being updated
$mail_id=trim($_REQUEST['sel']);
//save the value of selected to a variable
if (!$isPostBack) {
// Check for NOT postback, cuz we want to populate an empty form
$chosen = isset($_REQUEST['sel'])?$_REQUEST['sel']:99;
//look if the URL has a &sel= and a number otherwise give it a number not used
$optionTags ="<select name=\"recipient\" id=\"cfRecipient\" eform=\"Form Subject::1\"><option value=\"23\">Please Select</option>";
//This is the start of the select tag
foreach ($names as $name => $value){
$selected=($value == $chosen)? ' selected' : '';
$optionTags .= "<option value = \"".$value."\"".$selected.">".$name."</option>\n";
}
//loop thru the array looking for a value equal to sel, if you find one add selected in the option tag
$optionTags.="</select>";
//close the select tag
/* This was for testing purposes by using a [+debug+] placelholder somewhere within the template
if ($mail_id > 0){
$templates['tpl'] = str_replace('[+debug+]','Using '.$mail_id.' as the selected option value',$templates['tpl']);
}else{
$templates['tpl'] = str_replace('[+debug+]','No email specified',$templates['tpl']);
}
*/
$templates['tpl'] = str_replace('[+SelectBox+]',$optionTags,$templates['tpl']);
//Replace our placeholder [+SelectBox+] with the contents of the $optionTags variable
} else {
// The form has beed posted, let's not disturb the data.
}
return true; // A value of false will stop the eForm parser
}
?>
Other things we need to change are the page where we are displaying the form so it looks like this (or similar). Note the additional &eFormOnBeforeFormParse=`populate` parameter in our eform call and that we are calling [!SelectBoxParser!] which is the snippet containing our populate function. If this bit isn’t working correctly you will get a message saying that it can’t find said function (at least with FF)
Note the emails in the correct order to square up with the vaules in the array at the top and that &eFormOnBeforeFormParse is calling our function "populate"
The only other thing you need to do is add the [+SelectBox+] placeholder to your ContactForm tag.
Hope this helps someone as much as TobyL helped me.
Taff