treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Simple Contact Form Dropdown Menu Help

  • I am trying to get a simple contact form to work so I get an email when the form is submitted. It works great, by the way. However, I can't get it to work with my dropdown menu. Everything else works, so I am not sure why the dropdown doesn't work. Here is the code: (pretend I put the rest of the form code before and after the dropdown code)

        <select name="State" id="State">
          <option value>Website Design &amp; Development</option>
          <option value>Branding</option>
          <code><option value>Video Production</option>
              <option value>Printing</option>
              <option value>Specialty/Other</option>
            </select>
    

    and the php:

    <?php
    
    $EmailFrom = Trim(stripslashes($_POST['Email'])); ;
    $EmailTo = "titanvex@titanvex.com";
    $Subject = "Incoming Inquiry from titanvex.com";
    $FirstName = Trim(stripslashes($_POST['FirstName'])); 
    $State = Trim(stripslashes($_POST['State'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $Message = 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 .= "Full Name: ";
    $Body .= $FirstName;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Project Type: ";
    $Body .= $State;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    // send email 
    
    
    // redirect to success page 
    if (mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>")){
      print "http://www.titanvex.com/contact/sent\">";
    }
    else{
      print "";
    }
    ?>

    Any help would be greatly appreciated on this problem. When I get the email, everything is filled in, except for the part where I am trying to get 'State'. Thank you very much in advanced!

  • There is a stray 'code' tag in the select that could be slopping it up , also, you will need to make sure "Trim" is not capitalized...it needs to be all lowercase.

    But the actual issue is that you are not setting a value in the options...you should have something like this:

    http://jsfiddle.net/4DR6b/

  • Trim will work capitalised or not, but kgscott is on the money, should be kept as standard lower case.

  • Perfect. Works great. Thank you very much!

  • @andy_unleash yes, trim will work capitalized, but for convention sake (and mostly my sanity) it has to be all lower case! hahaha.