Jump to content

simple form parsing with dropdown select field-need help


simcoweb

Recommended Posts

I'm inserting a form field utilizing a dropdown selector so the person can select which department they wish for the email to be directed to. Depending on their selection the form results would be emailed to the respective address.

 

I am using this code to parse and send the form without the dropdown selection.

 

<?
@extract($_POST);
$name = stripslashes($name);
$email = stripslashes($email);
$department = stripslashes($department);
$message = stripslashes($message);

if(mail("[email protected]","Email from $name","
$message

(From $name, $email)","From: $email")){
echo "$name $email $message";
}*/
echo "Email Successfully Sent!<br />
<br />
Name: $name<br />Email: $email<br />Website: $website<br />Message: $message";
?>

 

And the form code:

<form id="my-form">
	<table>
	<tr><td>Name</td><td><input type="text" id="name" name="name" /></td></tr>
	<tr><td>Email<br /><small>(will never be published)</small></td><td><input type="text" id="email" name="email" /></td></tr>
	<tr><td>Department</td><td><select name="department">
<optgroup label="Department">
<option value="sales" name="sales">Sales</option>
<option value="customer service" name="customer service">Customer Service</option>
</optgroup></select></td></tr>
	<tr><td valign="top">Message</td><td><textarea cols="40" rows="5" name="message" id="message"></textarea></td></tr>
	<tr><td> </td><td><input type="button" value="Send" onclick="sendRequest();" />
	<input type="button" id="resetbut" name="resetbut" value="Reset" onclick="resetForm();"  /></td></tr>
	</table>
</form>

 

The key is that IF they select the Sales dept. then the email would be sent to sales@ and IF they select the Customer Service then it would go to customerservice@. Not sure how to code that properly to populate the $to slot in the mail(function). Just a bit of guidance, por favor :)

Ok, so basically I don't need to worry that the 'field' name 'department' has multiple choices, it will take the 'value' assigned to whatever choice they select and populate the $to variable with the front-end of the email and complete it with the $your_site content.

 

For some reason I was thinking I had to deal with an array issue of some sort since it was a drop down selection with multiple choices under one group name. Guess that's not the case, eh?

 

Thanks for your response!

Ok, so basically I don't need to worry that the 'field' name 'department' has multiple choices, it will take the 'value' assigned to whatever choice they select and populate the $to variable with the front-end of the email and complete it with the $your_site content.

 

For some reason I was thinking I had to deal with an array issue of some sort since it was a drop down selection with multiple choices under one group name. Guess that's not the case, eh?

 

Thanks for your response!

 

Yes, you are correct. You do not have to use an array here (and if you happen to come across a browser that sends an array of information when sending the value selected of a drop-down field, let me know).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.