...

View Full Version : Dropdowns not sending in email forms php



happeemom
03-20-2010, 10:04 PM
Hi everyone,

I need help, I cant figure out why my email form is not sending the dropdown menu information in the email. Everything else thats not a dropdown works fine and even validates, but not the dropdow options. Can someone help me.:rolleyes:
Below is the html page
[CODE]
<td width="596" class="pageName">Fill Out Our Form To Schedule An Appointment</td>
</tr>
<tr>
<td class="bodyText">
<form method="post" enctype="multipart/form-data" action="contact.php" accept-charset="utf-8">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td><h3 style="border-bottom:1px solid black;">Schedule An Appointment</h3></td>
</tr>
<tr>
<td>
<label for="First" style="float:left;width:140px;">First Name*</label><input type="text" name="First" id="First" maxlength="" style="width:100px;"><div style="clear:left;height:20px;"> </div>

<label for="Last" style="float:left;width:140px;">Last Name*</label><input type="text" name="Last" id="Last" maxlength="" style="width:200px;"><div style="clear:left;height:20px;"> </div>

<label for="Street" style="float:left;width:140px;">Street Address*</label><input type="text" name="Street" id="Street" maxlength="" style="width:200px;"><div style="clear:left;height:20px;"> </div>

<label for="Address2" style="float:left;width:140px;">Address 2</label><input type="text" name="Address2" id="Address2" maxlength="" style="width:200px;"><div style="clear:left;height:20px;"> </div>

<label for="City" style="float:left;width:140px;">City*</label><input type="text" name="City" id="City" maxlength="" style="width:100px;"><div style="clear:left;height:20px;"> </div>

<label for="Zip" style="float:left;width:140px;">Zip*</label><input type="text" name="Zip" id="Zip" maxlength="" style="width:100px;"><div style="clear:left;height:20px;"> </div>

<label for="email" style="float:left;width:140px;">E-Mail Address*</label><input type="text" name="email" id="email" maxlength="" style="width:200px;"><div style="clear:left;height:20px;"> </div>

<label for="EmailConf" style="float:left;width:140px;">Confirm E-Mail Address*</label><input type="text" name="EmailConf" id="EmailConf" maxlength="" style="width:200px;"><div style="clear:left;height:20px;"> </div>

<label for="Phone" style="float:left;width:140px;">Best Contact Phone* Number</label><input type="text" name="Phone" id="Phone" maxlength="" style="width:200px;"><div style="clear:left;height:20px;"> </div>

<label style="float:left;width:140px;" for="AppointType">I would Like An Appointment For:*</label><select name="AppointType" id="AppointType">
<option value="Estimate">New Unit Estimate</option>
<option value="Diagnostic">Diagnostic</option>
<option value="A/C Service">A/C Service</option>
<option value="Heater Service">Heater Service</option>
<option value="Warranty">Warranty</option>
<option value="Service Agreement Schedule">Yearly Maintenance</option>
</select><div style="clear:left;height:20px;"> </div>

<label style="float:left;width:140px;" for="Time">My Requested Appointment Time</label><select name="Time" id="Time">
<option value="Morning">Morning</option>
<option value="Noonish">Noonish</option>
<option value="Mid Afternoon">Mid Afternoon</option>
<option value="Evening">Evening</option>
</select>
<div style="clear:left;height:20px;"> </div>

<label style="float:left;width:140px;" for="Day[]">The Day I request for Service Is: <br />
( Hold Shift + Click For Multiple Selections)</label><select name="Day[]" multiple="MULTIPLE" id="Day[]">
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="This week">This Week</option>
<option value="Next Week">Next Week</option>
<option value="Any Available Day" selected="selected">Any Available Appointment</option>
</select>
<div style="clear:left;height:20px;"> </div>

<label style="float:left;width:140px;" for="System">My System is a :</label><select name="System" multiple="multiple" id="System">
<option value="Package" selected="selected">Package Unit</option>
<option value="Split System">Split System</option>
<option value="Heat Pump">Heat Pump</option>
<option value="Don't Know">Don't Know</option>
<option value="N/A">Not Applicable</option>
</select>
<div style="clear:left;height:20px;"> </div>

<label style="float:left;width:140px;" for="GasType">My Primary Type Of Gas is:</label>
<select name="GasType" multiple="multiple" id="GasType">
<option value="Natural Gas">Natural Gas</option>
<option value="Propane">Propane</option>
</select>
<div style="clear:left;height:20px;"> </div>

<label style="float:left;width:140px;" for="Age">I think The Age Of My System Is:</label><select name="Age" multiple="multiple" id="Age">
<option value="1-2 YO" selected="selected">1-2 Years Old</option>
<option value="3-6 YO">3-6 Years Old</option>
<option value="7-10 YO">7-10 Years Old</option><option value="11-15 YO">11-15 Years Old</option><option value="16-20 YO">16-20 Years Old</option><option value="21+ YO">21 Years +</option>
</select>
<div style="clear:left;height:20px;"> </div>

<label for="BrandName" style="float:left;width:140px;">The Brand Name I Have Or I'm Interested In Is:</label><input type="text" name="BrandName" id="BrandName" maxlength="200" style="width:300px;"><div style="clear:left;height:20px;"> </div>

<label for="Comments" style="float:left;width:140px;">Additional Requests, Comments or Description*</label><textarea name="Comments" id="Comments" style="width:400px;height:250px;">Additional Comments</textarea><div style="clear:left;height:20px;"> </div>

</td>
<tr>
<td align="right">
<!-- YOU CAN MODIFY THE TEXT WITHIN VALUE="" TO MODIFY YOUR BUTTON TEXT-->
<input type="submit" value=" Submit "> <input type="reset" value=" Reset ">
</td>
</tr>
</table>
</form> <p>&nbsp;</p>
[CODE]

---------------------------------
And the php code

[CODE]
<?php
$AppointType= $_POST['AppointType'];
$email = $_POST['email'];

if(!$_POST) exit;

//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$value = array ('First','Last','Street', 'Address2', 'City', 'Zip','email','EmailConf','Phone','AppointType','Time','Day[]','System','GasType', 'Age', 'BrandName', 'Comments');
$required = array('First','Last','Street','City','Zip','email','Phone');

$your_email = "$email";
$email_subject = "New Customer Inquiry ";
$email_content = "\n";
$mailheader = "From: ".$_POST["email"]."\r\n";

foreach($value as $key => $value){
if(in_array($value,$required)){
if ($key != 'email' && $key != 'First' && $key != 'Last' && $key != 'Street' && $key != 'City' && $key != 'Zip' && $key != 'Phone') {
if( empty($_POST[$value]) ) { print ("ALL FIELDS ARE REQUIRED* Please press your back button<br>"); exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";

}
}

if(mail("info@airspecialist.org",$email_subject, $email_content, "From: $email")) {
print 'Your message has been sent! We will be contacting you shortly.';
} else {
echo 'ERROR!';
}
echo "<BR>";
echo "<a href='index.html'>Return to our Home Page</a>";
}
?>
[CODE]

happeemom
03-21-2010, 06:28 PM
Please Anyone?? I'm trying to learn as I go, I'm not great at all this stuff, but I can get it if someone explains it to me... I really need your help. Please forgive me if I posted too much, this is my first time

kab012345
03-21-2010, 07:29 PM
It looks like the form is supposed to send multiple dropdown options if selected, right?

I would use checkboxes instead for multiple items, because I think it would be easier in my opinion especially since it is using an array.

happeemom
03-22-2010, 05:21 PM
Yeah, that seems like a great idea, but how do I get the information to be included in the email?? When I receive the email, it does not include any of the selection item at all, it doesnt even list them, what am I doing wrong?

Rowsdower!
03-24-2010, 07:25 PM
This is your PHP code:
<?php
$AppointType= $_POST['AppointType'];
$email = $_POST['email'];

if(!$_POST) exit;

//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$value = array ('First','Last','Street', 'Address2', 'City', 'Zip','email','EmailConf','Phone','AppointType','Time','Day[]','System','GasType', 'Age', 'BrandName', 'Comments');
$required = array('First','Last','Street','City','Zip','email','Phone');

$your_email = "$email";
$email_subject = "New Customer Inquiry ";
$email_content = "\n";
$mailheader = "From: ".$_POST["email"]."\r\n";

foreach($value as $key => $value){
if(in_array($value,$required)){
if ($key != 'email' && $key != 'First' && $key != 'Last' && $key != 'Street' && $key != 'City' && $key != 'Zip' && $key != 'Phone') {
if( empty($_POST[$value]) ) {
print ("ALL FIELDS ARE REQUIRED* Please press your back button<br>");
exit;
}
}
$email_content .= $value.': '.$_POST[$value]."\n";

}
}

if(mail("info@airspecialist.org",$email_subject, $email_content, "From: $email")) {
print 'Your message has been sent! We will be contacting you shortly.';
} else {
echo 'ERROR!';
}
echo "<BR>";
echo "<a href='index.html'>Return to our Home Page</a>";
}
?>

Now let's consider something:

if($errors==1) echo $error;
else{
$value = array ('First','Last','Street', 'Address2', 'City', 'Zip','email','EmailConf','Phone','AppointType','Time','Day[]','System','GasType', 'Age', 'BrandName', 'Comments');
$required = array('First','Last','Street','City','Zip','email','Phone');

$your_email = "$email";
$email_subject = "New Customer Inquiry ";
$email_content = "\n";
$mailheader = "From: ".$_POST["email"]."\r\n";

foreach($value as $key => $value){
...
}
...
}

You really should rename your variable for your list of labels to something OTHER THAN "$value".

But really, right now you should write to a moderator and ask to have your post moved into the PHP forum (don't re-post there, have a mod actually move this thread). You will get more and better help by following the rules and posting in the correct category.

tomws
03-24-2010, 07:28 PM
This line is in the wrong place, I think.

$email_content .= $value.': '.$_POST[$value]."\n";
Looks like it's inside of the if(in_array($value,$required)) test for required fields, so it's only adding the required fields to the $email_content variable. Move it outside of that if statement's closing bracket.


foreach($value as $key => $value)
{
if(in_array($value,$required))
{
if ($key != 'email' && $key != 'First' && $key != 'Last' && $key != 'Street' && $key != 'City' && $key != 'Zip' && $key != 'Phone')
{
if( empty($_POST[$value]) )
{
print ("ALL FIELDS ARE REQUIRED* Please press your back button<br>");
exit;
}
}
/* from here */
}
/* to here */
$email_content .= $value.': '.$_POST[$value]."\n";
}


Unrelated, but you may want to change the ID Day[] to Day in both the form and the form handler.

tomws
03-24-2010, 07:29 PM
But really, right now you should write to a moderator and ask to have your post moved into the PHP forum (don't re-post there, have a mod actually move this thread). You will get more and better help by following the rules and posting in the correct category.

They may be able to merge the threads, which would help.

happeemom
03-24-2010, 07:47 PM
This line is in the wrong place, I think.

$email_content .= $value.': '.$_POST[$value]."\n";
Looks like it's inside of the if(in_array($value,$required)) test for required fields, so it's only adding the required fields to the $email_content variable. Move it outside of that if statement's closing bracket.


foreach($value as $key => $value)
{
if(in_array($value,$required))
{
if ($key != 'email' && $key != 'First' && $key != 'Last' && $key != 'Street' && $key != 'City' && $key != 'Zip' && $key != 'Phone')
{
if( empty($_POST[$value]) )
{
print ("ALL FIELDS ARE REQUIRED* Please press your back button<br>");
exit;
}
}
/* from here */
}
/* to here */
$email_content .= $value.': '.$_POST[$value]."\n";
}




:eek: YAHOOOOOOOOOOOOOOOOO!!!!! I could just kiss you!! Thank you, thank you, thank you!!!! :D :D I am super happy! How the heck did I miss that?? Those stupid brackets, lol! IT WORKED! tomws, you are the man! Thanks guys for your help..... I can finally sleep! I will mark this as solved and see if I can get a moderator to move it to php. Thank you all for your help.

happeemom
03-24-2010, 07:55 PM
um... one more question.....how do I contact a moderator to get the thread moved? :confused:

tomws
03-24-2010, 08:08 PM
um... one more question.....how do I contact a moderator to get the thread moved? :confused:

2 ways. 1) hit the flag link in the user box to the left, or 2) scroll to the bottom of the forum and pick a mod's name.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum