Hi hicksticks2001,
First off, it's not good practice to include email addresses on a webpage (with the possible exception of a closed intranet). It's also going to make our task easier if we put the email addresses into the OnSubmit code.
For the html code I'd use something like this:
<select name="subject" id="subject" tabindex="10" >
<option value="">Select One...</option>
<?php
$dept_array = array('city_admin' => 'City Administration', 'billing' => 'Billing Department', 'building' => 'Building Department', . . ., 'general' => 'General');
foreach ( $dept_array as $key => $value ) {
echo "<option value='$key' >$value</option>";
}
?>
</select>
<input type="hidden" value="" />
The section in <?php tags just loops through the dept array generating an option for each entry. If the department list ever changes then you can just change the array entries. The hidden entry is just a placeholder for our email address.
The select box will return a value in the $_POST array which is either "" or one of the array keys ("" shouldn't happen but we'll handle it anyhow).
In the Onsubmit box we use a similar code to look up the $_POST value and set the corresponding email address.
<?php
// $subject = $_POST['subject']; // code for Joomla 1.0.x
$subject = JRequest::getVar('subject','', 'post', 'string', '' ); // code for Joomla 1.5.x
$email_array = array('city_admin' => 'jana.sousa', 'billing' => 'melinda.wall', 'building' => 'Building_Department', . . . , 'general' => 'rick.spalding');
if ( isset($subject) && in_array($subject, $email_array) {
$email = $email_array[$subject]."@losbanos.org";
} else {
$email = $email_array['general']."@losbanos.org";
}
// $_POST['email'] = $email; // code for Joomla 1.0.x
JRequest::setVar('email', $email, 'string', '' ); // code for Joomla 1.5.x
?>
Here we set $subject equal to the value returned by the form (there are slightly different syntaxes for Joomal 1.0 and 1.5); then look up $subject in an email address array. This has the same array keys as the earlier one but this time the values are the name part of the email address. If there is no matching value then we'll use the 'general' address. We add the domain name to the email address (just makes the array shorter) and put the email address into the 'email' placeholder we created with the hidden field.
You can now use 'email' (no quotes) in the Special Fields tab to direct your email, and use {email} if you need to in the email template.
At least this is how it should work - there is a little bug in some versions of ChronoForms which requires a valid email address in the General tab before you can save your form. If you hit this problem then you can put a dummy address in there like [email]user@example.com[/email] and overwrite it in the OnSubmit beore code with
<?php
$rows[0]->extraemail = $email;
?>
Bob
PS None of this code is tested and so it may need de-bugging.