0

我正在使用我在网上找到的 jQuery Mobile Form 脚本。一切正常,除了 input="radio" 按钮。无论如何,我都不是 jQuery 专家,所以我希望这里有人可以帮助我。

设置

表单脚本包含 3 个文件:send.php、contact.js 和移动标记。有问题的代码示例如下:

移动标记:

<div data-role="fieldcontain">
  <fieldset data-role="controlgroup" data-type="horizontal">
   <legend>Doctor Type:</legend>
   <input type="radio" name="doctortype" id="dmd" value="dmd"/>
    <label for="dd">D.D.</label>
   <input type="radio" name="doctortype" id="dds" value="dds" />
    <label for="do">D.O.</label>
  </fieldset>
</div>

联系.js

$('#send-feedback').live("click", function() {
var url = 'api/send.php';
var error = 0;
var $contactpage = $(this).closest('.ui-page');
var $contactform = $(this).closest('.contact-form');
$('.required', $contactform).each(function (i) {
    if ($(this).val() === '') {
        error++;
    }
}); // each
if (error > 0) {
        alert('Please fill in all the mandatory fields. Mandatory fields are marked with an asterisk *.');
} else {
    var doctortype = $contactform.find('input[name="doctortype"]').val();
    var firstname = $contactform.find('input[name="firstname"]').val();
    var surname = $contactform.find('input[name="surname"]').val();
    var dob = $contactform.find('input[name="dob"]').val();
    var zip = $contactform.find('input[name="zip"]').val();
    var how = $contactform.find('select[name="how"]').val();
    var email = $contactform.find('input[name="email"]').val();
    var message = $contactform.find('textarea[name="message"]').val();  

    //submit the form
    $.ajax({
        type: "GET",
        url: url,
        data: {doctortype:doctortype, firstname:firstname, surname:surname, dob:dob, zip:zip, how:how, email:email, message:message},
        success: function (data) {
            if (data == 'success') {
                // show thank you
                $contactpage.find('.contact-thankyou').show();
                $contactpage.find('.contact-form').hide();
            }  else {
                alert('Unable to send your message. Please try again.');
            }
        }
    }); //$.ajax

}
return false;
});

发送.php

<?php
header('content-type: application/json; charset=utf-8');

if (isset($_GET["firstname"])) {
$doctortype = strip_tags($_GET['doctortype']);
$firstname = strip_tags($_GET['firstname']);
$surname = strip_tags($_GET['surname']);
$dob = strip_tags($_GET['dob']);
$zip = strip_tags($_GET['zip']);
$how = strip_tags($_GET['how']);
$email = strip_tags($_GET['email']);
$message = strip_tags($_GET['message']);
$header = "From: ". $firstname . " <" . $email . ">"; 

$ip = $_SERVER['REMOTE_ADDR'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];
$today = date("F j, Y, g:i a");    

$recipient = 'MYEMAIL@gmail.com';
$subject = 'Contact Form';
$mailbody = "
Doctor Type: $doctortype
First Name: $firstname
Last Name: $surname
Date of Birth: $dob
Zip Code: $zip
How Did You Learn About Us: $how
Message: $message

IP: $ip
Browser info: $httpagent
Referral: $httpref
Sent: $today
";
$result = 'success';

if (mail($recipient, $subject, $mailbody, $header)) {
    echo json_encode($result);
}
}
?>

该表格本身可以正常工作。用户填写信息,点击“发送”,我会收到一封包含信息的电子邮件。但是,我无法获取要解析和发送的检查收音机的值。

我花了很多时间试图让检查的无线电值通过必要的步骤。

这就是问题所在。我在 SO 和其他不同的地方在线查看了无数类似的帖子,包括 jQuery Mobile 文档。无济于事。

任何帮助深表感谢!

4

1 回答 1

0

你的 jQuery 在做什么?似乎没有必要做任何 jQuery/JavaScript。如果没有它,表单应该将您的单选按钮的值发送到 $_GET['doctortype'] (假设您的表单方法是 get)。

于 2013-10-10T01:09:44.823 回答