联系表单不发送下拉值

问题描述 投票:0回答:1

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

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="[email protected]";
  $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>
php drop-down-menu html-select contact-form
1个回答
0
投票

欢迎Maria;)

第一:

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

“type”实际上不是“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();
© www.soinside.com 2019 - 2024. All rights reserved.