2013-10-10 6 views
0

온라인으로 찾은 jQuery Mobile Form 스크립트를 사용하고 있습니다. input = "radio"버튼을 제외한 모든 것이 잘 작동합니다. 나는 어떤 의미로 jQuery 전문가가 아니기 때문에 여기 누군가가 나를 도울 수 있기를 바라고있다.jQuery Mobile PHP 폼 - 라디오 버튼 값 확인

설치

양식 스크립트는 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 문서를 포함하여 SO와 다른 여러 장소에서 수많은 유사한 게시물을 보았습니다. 아무 소용이 없다.

도움을 주시면 감사하겠습니다.

답변

0

jQuery는 무엇을하고 있습니까? jQuery/JavaScript를 사용하지 않아도됩니다. 양식은 라디오 단추의 값을 $ _GET [ 'doctortype']없이 보내야합니다 (양식 메서드가 get이라고 가정).

+0

방금 ​​Contact.js 및 Send.php의 전체 내용을 게시했습니다. Send.php가 데이터의 유효성을 확인하고 보내는 것 같습니다. 나는 $ doctortype = strip_tags ($ _GET [ 'doctortype']);를 $ _GET [ 'doctortype']'로 대체했지만 운이 없다. – Brian

+0

그래, 문제가 생겼다. 다른 모든 것이 작동한다고 가정하면 (다른 값은 OK를 통해 전달됩니다) JavaScript의 한 행을 변경해야합니다. var doctortype = $ contactform.find ('input [name = "doctortype"] : checked') .val(); – Mark