【问题标题】:select option not giving value in Wordpress contact form PHP选择选项在 Wordpress 联系表单 PHP 中没有给出值
【发布时间】:2015-01-08 06:59:27
【问题描述】:

我正在编辑一个 Wordpress 主题联系表。我正在添加一个选择下拉菜单,根据选择的选项,电子邮件将被发送到不同的地址。 我的 WP 选项工作正常,我对其进行了测试。问题是选择框。出于某种原因,选择值在电子邮件中返回空白,因为它返回空白,我无法使其余的逻辑功能正常。

                                <div class="column1">
                                <select class="selectclass" name="question" id="question">
                                    <option value ="9" selected>What is your question?</option>
                                    <option value ="1">I would like to see a demo</option>
                                    <option value ="2">I’d like to learn more about native advertising</option>
                                    <option value ="3">I am a publisher and  interested in seeing products</option>
                                    <option value ="4">I am an advertiser and I want to speak to a sales representative</option>
                                    <option value ="5">I am interested in partnering with Content That Works</option>
                                    <option value ="6">I have an issue with my billing</option>
                                    <option value ="7">There is something technically wrong with your website</option>
                                    <option value ="8">Other questions</option>
                                </select>
                                </div>




<?php
require_once('recaptchalib.php');
require('../../../../wp-blog-header.php');
global $qode_options_proya;

$publickey = $qode_options_proya['recaptcha_public_key'];
$privatekey = $qode_options_proya['recaptcha_private_key'];

if ($publickey == "") $publickey = "6Ld5VOASAAAAABUGCt9ZaNuw3IF-BjUFLujP6C8L";
if ($privatekey == "") $privatekey = "6Ld5VOASAAAAAKQdKVcxZ321VM6lkhBsoT6lXe9Z";

$resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
$quest = $_POST["question"];

$use_captcha = $qode_options_proya['use_recaptcha'];
if ($resp->is_valid || $use_captcha == "no") {
    ?>success<?php

    $email_to = $qode_options_proya['native_mail'];

    $email_from = $qode_options_proya['email_from'];
    $subject = $qode_options_proya['email_subject'];

    $text = "Name: " . $_POST["name"] . " " . $_POST["lastname"] . "\n";
    $text = "Question: " . $_POST["question"] . "\n";
    $text .= "Email: " . $_POST["email"] . "\n";
    $text .= "WebSite: " . $_POST["website"] . "\n";
    $text .= "Message: " . $_POST["message"];

    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/plain; charset=utf-8" . "\r\n";
    $headers .= "From: '".$_POST['name']." ".$_POST['lastname']."' <".$email_from."> " . "\r\n";

    $result = wp_mail($email_to, $subject, $text, $headers);


    if(!$result) {
        global $phpmailer;
        var_dump($phpmailer->ErrorInfo);
    }
}
else {
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .  "(reCAPTCHA said: " . $resp->error . ")");
}
?>

任何帮助将不胜感激,谢谢。

更新 这是完整的页面...... http://pastebin.com/vyT6J4PH http://pastebin.com/kk2Byy6S

【问题讨论】:

  • 数据是如何发送到服务器的?
  • 选择的是哪个元素?如果没有表单的代码,我们无法重现问题。
  • @charlietfl 它是使用 wordpress 函数发送的 $result = wp_mail($email_to, $subject, $text, $headers);
  • @JeremiahWinsley select元素在上面,它的名字和ID是“question”。
  • 来自客户端的数据不是通过wordpress函数发送的,它要么是通过ajax提交,要么是默认表单提交

标签: php wordpress select options


【解决方案1】:

您的表单的问题在于 AJAX 提交功能。

        challengeField = $j("input#recaptcha_challenge_field").val();
        responseField = $j("input#recaptcha_response_field").val();
        name =  $j("input#fname").val();
        lastname =  $j("input#lname").val();
        email =  $j("input#email").val();
        website =  $j("input#website").val();
        message =  $j("textarea#message").val();

        var form_post_data = "";

        var html = $j.ajax({
        type: "POST",
        url: "<?php echo QODE_ROOT; ?>/includes/ajax_mail.php",
        data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField + "&name=" + name + "&lastname=" + lastname + "&email=" + email + "&website=" + website + "&message=" + message,
        async: false
        }).responseText;

选择元素没有与其他元素一起提交。

        question = $j("select#question").val();

        data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField + "&name=" + name + "&lastname=" + lastname + "&email=" + email + "&website=" + website + "&message=" + message + "&question=" + question,

应该可以解决您的问题。

【讨论】:

  • 谢谢。我想我忽略了这一点,菜鸟的错误。但现在由于某种原因我得到“未定义”问题:未定义电子邮件:new@email.com 网站:sdfgb 消息:d
  • 没关系,我忘了我删除了选择 ID,一旦我把它放回去,一切都很好!谢谢!
猜你喜欢
  • 2015-06-23
  • 1970-01-01
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
  • 2021-05-27
  • 2020-01-11
  • 1970-01-01
  • 2018-06-09
相关资源
最近更新 更多