I set up a feedback form with a similar requirement using events. You can probably simplify it - I wanted to the client to be able to update the addresses from a TV without editing chunks or files.
The components of my solution are the form, the eForm call, two eForm extender functions (plus one for validation), a chunk and the TV.
The subject field is called
cSubject, and this part of the HTML is inserted using a placeholder called
[+rhMessageList+]
The eForm call looks like this:
[!eFormExtenders?!]
[!eForm? &formid=`contactForm` &tpl=`pkMessageForm` &eFormOnValidate=`valext`
&subject=`((cSubject))` &report=`pkResponseMessage`
&eFormOnBeforeMailSent=`sendMessage` &eFormOnBeforeFormMerge=`setMessages`
&sendirect=`1`!]
(Validation includes a custom check that the sender has included either a phone number or an email address. I think the
&sendirect parameter is required for the method described here.)
The extender functions:
<?php
/* extensions to eForm for Contacts page emails to different addresses */
function setMessages(&$fields) {
/* set up options for dropdown list held in chunk rhMessageList
save messages in placeholder for use by sendMessage */
global $modx;
$options = explode('||',$modx->getChunk('rhMessageList'));
$select = "\t" . '<span class="edLabel"> </span>';
$select .= "\t" . '<span class="edField">';
$select .= "\t" . '<select name="messageType" id="messageType" size="1">' . "\n";
foreach ($options as $option) {
$item = explode('==', $option);
$select .= "\t" . '<option value="' . $item[1] . '"';
$select .= ($item[1] == 0) ? 'selected="selected"' : NULL;
$select .= '>' . $item[0] . "</option>\n";
}
$select .= "\t</select>\n\t</span>\n";
$fields['rhMessageList'] = $select;
}
function valext(&$fields,&$vMsg,&$rMsg) {
/* Require either phone number or email or both for contact form */
if (empty($fields['cMail']) AND empty($fields['cPhone'])) {
$rMsg[] = '<br />An email address or phone number';
}
/* Check something is selected from drop-down list, */
if ($fields[recipient] == '0') {
$rMsg[] = '<br />Please select a message subject from the list';
}
return true;
}
function sendMessage(&$fields) {
// set up email adress and response form fields when form submitted
global $modx;
// recreate messages for use as subject field
$options = explode('||',$modx->getChunk('rhMessageList'));
$option = explode('==',$options[$fields['messageType']]);
$fields['cSubject'] = trim($option[0]);
// Match email address, stored as TV rhMailAddresses in format
// <1>mailaddress1||<2>mailaddress2|| etc., (with returns to be stripped)
$mailAddresses = $modx->getTemplateVar('rhMailAddresses','id');
$mailAddresses = explode('||',$mailAddresses['value']);
$recipientAddress = trim($mailAddresses[--$fields['messageType']]);
$recipientAddress = ereg_replace('<.*>','',$recipientAddress);
$fields['email'] = $recipientAddress;
/* set up strings for empty fields */
if (empty($fields['cPhone'])) {
$fields['cPhone'] = '(no phone number supplied)';
}
if (empty($fields['cMail'])) {
$fields['cMail'] = '(no email supplied)';
}
$fields['cText'] = str_replace("\n\n","\n",$fields['cText']);
$fields['cText'] = str_replace("\n","<br />\n",$fields['cText']);
}
?>
The
rhMessageList chunk:
- Please select message subject -==0||Request for details==1||Message to X ==2||Message to Y ==3||Comment on the website==4
rhMailAddresses is simply a textarea TV, with content in the format detailed in the extender function:
Hope this meets your needs

KP