0
votes

I am editing a Wordpress themes contact form. I am adding a select dropdown menu, based on which option is selected, the email will be sent to a different address. My WP options works fine, I tested it. The problem is the select box. For some reason the select value comes back blank in the email, since its coming back blank, I cant make the rest of my logic function properly.

                                <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 . ")");
}
?>

Any help would be greatly appreciated, thank you.

UPDATE Here are the full pages.... http://pastebin.com/vyT6J4PH http://pastebin.com/kk2Byy6S

1
how is the data sent to server? - charlietfl
Which element is the select? We can't reproduce the problem without the code for the form. - Jeremiah Winsley
@charlietfl it is sent using the wordpress function $result = wp_mail($email_to, $subject, $text, $headers); - Michael Christopher Martire
@JeremiahWinsley The select element is above, its name and ID is "question". - Michael Christopher Martire
data from client is not sent with a wordpress function, it's either submitted by ajax or default form submit - charlietfl

1 Answers

0
votes

The problem with your form is the AJAX submit function.

        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;

The select element isn't getting submitted along with the rest.

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

and

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

should fix your problem.