联系表单未发送下拉值

时间:2019-03-15 10:04:43

标签: php drop-down-menu html-select contact-form

我创建了一个带有下拉列表值的联系表单,如下所示,但这些值未发送到我的电子邮件中-除下拉列表值外,其余所有值均通过发送。对此的任何帮助将不胜感激,因为我所做的研究似乎没有帮助。

Here is my JS

submitSuccess: function($form, event) {
    event.preventDefault(); // prevent default submit behaviour
    // get values from FORM
    var name = $("input#name").val();
    var email = $("input#email").val();
    var radio = $("input#radio").val();
    var message = $("textarea#message").val();
    var firstName = name; // For Success/Failure Message
    // Check for white space in name for Success/Fail message
    if (firstName.indexOf(' ') >= 0) {
      firstName = name.split(' ').slice(0, -1).join(' ');
    }
    $.ajax({
          url: "assets/contact_me.php",
          type: "POST",
          data: {
            name: name,
            radio: radio,
            email: email,
            message: message,
            submit: 1
          },
Here is my PHP <?php if (isset($_POST['submit'])) {
  var_dump($_POST);
  $name=$_POST['name'];
  $email=$_POST['email'];
  $radio=$_POST['radio'];
  $message=$_POST['message'];
  $mailTo="info@margineco.com";
  $subject="New message from ".$name;
  $headers="From: ".$email;
  $txt="You have received an email from ".$name." with regards to ".$radio.".\n\n".$message;
  mail($mailTo, $subject, $txt, $headers);
  header("Location: index.html?mailsend");
}

?>
Here is my HTML

<div class="row control-group">
  <div class="form-group col-xs-12 controls">
    <label>Plan Option<span>*</span></label>
    <div class="dropdown">
      <select class="form-control" id="radio" required data-validation-required-message="Please choose a option from the dropdown menu.">
        <option type="radio" value="0" selected>Please select...</option>
        <option type="radio" value="option1">General Inquiry</option>
        <option type="radio" value="option2">Market Intelligence</option>
        <option type="radio" value="option3">Economic Analysis</option>
        <option type="radio" value="option4">Industry Forecasts</option>
      </select>
    </div>
    <p class="help-block"></p>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

欢迎玛丽亚;)

第一:

<option type="radio" value="option4">Industry Forecasts</option>

“类型”实际上不是“选项”的有效选项:https://developer.mozilla.org/de/docs/Web/HTML/Element/option应该是:

<option value="option4">Industry Forecasts</option>

第二:

var radio = $("input#radio").val();

不会给您任何结果,因为您要从“选择”而不是“输入”中进行选择。应该是:

var radio = $("select#radio").val();