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("test@example.com","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 :)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.