Jump to content

[SOLVED] Drop down in form isn't working properly ...


prettikittie

Recommended Posts

Hi,

 

I've been searching everywhere to find the fix for my drop down issue, but sadly, I can't seem to grasp it. I'm fairly new at php.

 

I'm simply trying to get the drop down menu of my form to email the selected option but to no avail, the 'Location' is always returned to me empty. Somehow, I ended up with the answer 'Submit' with one of my attempts.

 

I'd really appreciate any help/insight into what I'm doing wrong ...

 

Thanks muchly ~`

 

I'll only include the sections that are obviously not correct ... and I've only one location example on there.

 

Thanks again.

 

<?php

$EmailFrom = "$Name";
$EmailTo = "xxx";
$Subject = "";
$Name = Trim(stripslashes($_POST['Name'])); 
$Phone = Trim(stripslashes($_POST['Phone'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
$Message = "";
foreach ($_POST as $Locations => $Texas) {
$Message .= $Locations . ": " . $Texas . "\n";
} 

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $Location;
$Body .= "\n";
$Body .= "Request: ";
$Body .= $Request;
$Body .= "\n";

Hi, thanks for the reply ...

 

That section of the form is:

 

<strong>Location:</strong> <br />
			<select name="Locations">
			<option value=" "> </option>
				<option value="Texas">Texas</option>
				<option value="Florida">Florida</option>
<option value="Maine">Maine</option>

			</select>

 

Thanks for your help.

 

The code looks the way it does because I'm not sure of how to do it Lol The drop down thing has me stumped!

I've no php at all in the form ...

 

If I try placing this above that section - how to I edit this properly:

 

<?php

$EmailFrom = "$Name";
$EmailTo = "xxx";
$Subject = "";
$Name = Trim(stripslashes($_POST['Name'])); 
$Phone = Trim(stripslashes($_POST['Phone'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 
$Message = "";
foreach ($_POST as $Locations => $Texas) {
$Message .= $Locations . ": " . $Texas . "\n";


 

It keeps giving me an error once I remove the empty string, I don't think I'm using the ';' and such correctly.

 

Sorry, I followed a tutorial for the form, however it didn't have any drop-downs in it ~

 

Thanks, Jen

<?php
$EmailFrom = "$Name";
$EmailTo = "xxx";
$Subject = "";
$locations= htmlspclchars(Trim(stripslashes$_POST['Locations'])));
$Name = htmlspclchars(Trim(stripslashes($_POST['Name']))); 
$Phone = htmlspclchars(Trim(stripslashes($_POST['Phone']))); 
$Email = htmlspclchars(Trim(stripslashes($_POST['Email']))); 
$Message = htmlspclchars(Trim(stripslashes($_POST['Message']))); 
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $locations;
$Body .= "\n";
$Body .= "Request: ";
$Body .= $Request;
$Body .= "\n";
?>

Now prepare the email and mail it, let me see when you are all done.

Be sure to check your scripts for consitancey. Ex $location != $locations != $Location != $Locations ...

Thanks WolfRage,

 

But I'm getting an error - line 5, which is:

 

$locations= htmlspclchars(Trim(stripslashes$_POST['Locations'])));

 

I have to admit this wasn't as easy as I thought it would be!

 

Thank you again for your time, I appreciate it `

Sorry WolfRage ... still getting the empty location when the forms submitted ...

 

I changed this just a little - added the ')' after stripslashes. The ntire code, as maybe I'm missing something?!

 

I've also the tiny bit of php you'd suggested earlier placed just above the Locations section of the form.

 

<?php

$EmailFrom = "$Name";
$EmailTo = "xxx";
$Subject = "xxx";
$locations= htmlspecialchars(Trim(stripslashes($_POST['Locations'])));
$Name = htmlspecialchars(Trim(stripslashes($_POST['Name']))); 
$Phone = htmlspecialchars(Trim(stripslashes($_POST['Phone']))); 
$Email = htmlspecialchars(Trim(stripslashes($_POST['Email']))); 
$Message = htmlspecialchars(Trim(stripslashes($_POST['Message']))); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $Location;
$Body .= "\n";
$Body .= "Request: ";
$Body .= $Request;
$Body .= "\n";


// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?> 

 

 

 

 

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.