2013-10-10 68 views
0

我正在使用我在网上找到的jQuery Mobile Form脚本。一切工作正常,除了input =“radio”按钮。我不是任何方式的jQuery专家,所以我希望这里有人能帮助我。jQuery Mobile PHP表单 - 获取已检查的单选按钮值

THE SETUP

形式脚本包含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> 

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

Send.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 = '[email protected]'; 
$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); 
} 
} 
?> 

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

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

其中存在问题。我在网上查看过无数次类似的帖子,包括jQuery Mobile文档。无济于事。

任何帮助非常感谢!

回答

0

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

+0

我刚刚发布Contact.js和Send.php的全部内容。看来Send.php正在验证和发送数据。我用'$ _GET ['doctortype']'替换了'$ doctortype = strip_tags($ _ GET ['doctortype']);',但没有运气。 – Brian

+0

好的,我看到了问题。假定其他一切工作(你的其他值是通过确定未来的),那么你就需要改变你的JavaScript的一行: VAR doctortype = $ contactform.find(“输入[名称=‘doctortype’]:勾选”)。VAL (); – Mark