Below is the &eFormOnBeforeFormParse function I’m using. Hope you can pick out what you need from it.
I’m probably making things more complicated than necessary using the same form for a standard feedback page (with options to send comments to the "society", the charity the site is for, or to the web team), and links for the committee listing page to send an email to specific committee members. Clicking on a committee member link results in the member’s ID being sent in the query string, ’?message=nn’.
The committee names and emails are in a database table; the addresses for general correspondence and the webmaster are in the same table, with negative ID numbers. I wanted to avoid posting naked email addresses anywhere, even a hidden field, so I use the ID to pass info between calls to the form.
The main point is that a successful submission sets $fields[’email’], and this what &sendirect will use, regardless of what the fields on your form are called.
function selectMessageForm(&$fields,&$templates) {
/* Select email recipient from committee member's database record
Present standard form if no request for individual, or if no associated address */
global $modx;
$stdLegend = '<legend>Email</legend>';
$stdOptions = <<<OPTO
<div id="cMessage">
<label for="cText">Message</label>
<span class="cRbutton"><input type="radio" id="tosoc" name="whofor" value="soc" [+socCheck+]/> <label for="tosoc"> to society</label></span>
<span class="cRbutton"><input type="radio" id="toweb" name="whofor" value="web" [+webCheck+]/><label for="toweb"> to web team</label></span>
</div>
OPTO;
if (!isset($_POST['formid'])) {
$fields['legend'] = $stdLegend;
$fields['optionButtons'] = $stdOptions;
$modx->setPlaceholder('socCheck','checked="checked"');
$fields['randigit'] = rand(1001,9876);
if (isset($_REQUEST['message'])) {
if ($record = $modx->db->select('*','ms_committee','ID='.$_REQUEST['message'])) {
$row = $modx->db->getRow($record);
if (!empty ($row['email'])) {
$fields['optionButtons'] = '';
$fields['id'] = '<input type="hidden" name="cid" value="'.$row['ID'].'" />';
$fields['who'] = "\n".'<input type="hidden" name="whofor" value="member" />';
$fields['legend'] = '<legend>Email to '.$row['name'].'</legend>';
} else {
return true; // no email for this ID; present standard form
}
}
}
// Postback - set email address for &sendirect to use
} else {
if ($_POST['whofor'] == 'member') {
if ($record = $modx->db->select('*','ms_committee','ID='.$_POST['cid'])) {
$row = $modx->db->getRow($record);
$fields['legend'] = '<legend>Email to '.$row['name'].'</legend>';
$fields['optionButtons'] = '';
$fields['id'] = '<input type="hidden" name="cid" value="'.$row['ID'].'" />';
$fields['who'] = "\n".'<input type="hidden" name="whofor" value="member" />';
$fields['reportName'] = $row['name'];
}
} else {
$fields['legend'] = $stdLegend;
$fields['optionButtons'] = $stdOptions;
$fields['whofor'] = $_POST['whofor'];
if ($_POST['whofor'] == 'soc') {
$modx->setPlaceholder('socCheck','checked="checked"');
$record = $modx->db->select('email','ms_committee','name="correspondence"');
$fields['reportName'] = 'the society';
} else {
$modx->setPlaceholder('webCheck','checked="checked"');
$record = $modx->db->select('email','ms_committee','name="webmaster"');
$fields['reportName'] = 'the web team';
}
$row = $modx->db->getRow($record);
}
$fields['email'] = $row['email'];
}
}

KP