我尝试在jquery php 4 phonegap中创建一个联系表单,我的问题如何才能从php获得成功?或者如果我可以尝试其他解决方案,但目前没有想法4 ^^ 很多
P.S。表单有效(如果我删除响应成功表格js)
index.js
$(document).on('pageinit', function() {
$('#send').click(function() {
var url = 'send02.php';
var error = 0;
var $contactpage = $(this).closest('.ui-page');
var $contactform = $(this).closest('.contact-form02');
$('.required', $contactform).each(function(i) {
if($(this).val() === '') {
error++;
}
});
// each
if(error > 0) {
alert('Inserisci tutti i campi obbligatori segnati con asterisco*.');
} else {
var email = $contactform.find('input[name="email"]').val();
var datetime = $contactform.find('input[name="datetime"]').val();
var mobilephone = $contactform.find('input[name="mobilephone"]').val();
var selectnative4 = $contactform.find('select[name="selectnative4"]').val();
var message = $contactform.find('textarea[name="message"]').val();
//submit the form
$.ajax({
type : "POST",
url : url,
data : {
email : email,
datetime : datetime,
mobilephone : mobilephone,
selectnative4 : selectnative4,
message : message
},
success : function(data) {
if(data == 'success') {
// show thank you
$contactpage.find('.contact-thankyou').show();
$contactpage.find('.contact-form').hide();
} else {
alert('Impossibile inviare il messaggio. Per piacere riprova.');
}
}
});
//$.ajax
}
return false;
});
});
和send.php
<?php
header('content-type: application/json; charset=utf-8');
if (isset($_GET["email"])) {
$email = strip_tags($_GET['email']);
$datetime = strip_tags($_GET['datetime']);
$mobilephone = strip_tags($_GET['mobilephone']);
$selectnative4 = strip_tags($_GET['selectnative4']);
$message = strip_tags($_GET['message']);
$header = "From: ". $firstname . " <" . $email . ">rn";
$ip = $_SERVER['REMOTE_ADDR'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];
$today = date("F j, Y, g:i a");
$recipient = 'mark@facebook.com';
$subject = 'Prenotazione Online';
$mailbody = "
Nominativo: $email
Telefono: $mobilephone
data prenotazione: $datetime
Scelta dal Menù: $selectnative4
Messaggio: $message
in data: $today
";
$result = 'success';
if (mail($recipient, $subject, $mailbody, $header)) {
echo json_encode($result);
}
}
?>