我尝试了很多次,访问了很多论坛,但找不到答案。请不要发布它与其他帖子相似。试着帮我解决这个问题。
HTML 表单:
<form action="" method="post" id="bookingForm">
<div id="radiobutton">
<input type="radio" name="trip" id="oneway" value="oneway" checked/> Oneway
<input type="radio" name="trip" id="return" value="return"/> Return
</div>
<br/>
From:<input id="boarding" type="text" maxlength="40" class="user_input" size="18" name="boarding" value="Hyderabad"/>
To:<input id="landing" type="text" maxlength="40" class="user_input" size="18" name="landing"/>
<br/><br/><br/>
Onward:<input id="datepick" name="onward" class="user_input" size="15" />
Return: <input id="datepick2" name="return" class="user_input" size="15" />
<br/><br/><br/>
Your Name:<input id="pax_name" type="text" name="pax_name" class="user_input" size="25" maxlength="50"/>
<br/><br/>
Contact number:<input id="pax_contact" type="text" maxlength="14" name="pax_contact" class="user_input" size="25"/>
<br/><br/>
Email:<input id="pax_email" name="pax_email" class="user_input" size="25"/>
<br/><br/>
<center>
<input id="submit" type="button" value="Request" />
用于发送电子邮件的 process.php:
<?php
$trip=$_POST['trip'];
$boarding=$_POST['boarding'];
$landing=$_POST['landing'];
$onward=$_POST['onward'];
$return=$_POST['return'];
$pax_name=$_POST['pax_name'];
$pax_contact=$_POST['pax_contact'];
$pax_email=$_POST['pax_email'];
$to='anvesh@bsbtravels.com,anvifriend@gmail.com';
$subject='Booking Form Query';
$body=
'Name: '.$pax_name."\n".
'Contact Number: '.$pax_contact."\n".
'Trip: '.$trip."\n".
'From: '.$boarding."\n".
'To: '.$landing."\n".
'Onward Date: '.$onward."\n".
'Return Date: '.$return."\n";
$headers='From: '.$pax_name.'<'.$pax_email.'>';
mail($to,$subject, $body, $headers)
?>
jQuery代码:
$(document).ready(function(){
$('#submit').click(function(){
var boarding=$('#boarding').val();
var landing=$('#landing').val();
var datepick=$('#datepick').val();
var datepick2=$('#datepick2').val();
var pax_name=$('#pax_name').val();
var pax_contact=$('#pax_contact').val();
var pax_email=$('#pax_email').val();
if($('#landing').val().length<3 || $('#boarding').val().length<3 || $('#datepick').val().length<3 || $('#pax_name').val().length<3 || $('#pax_contact').val().length<8 || $('#pax_email').val().length<3){
$('#bookfail').attr('title','Sending Failed!').text('Please Enter valid information. All fields are required').dialog({buttons:{'Ok':function(){
$(this).dialog('close');
}},closeOnEscape:true,draggable:false,resizable:false,modal:true});
}else{
var VarData='boarding='+boarding+'&landing='+landing+'&datepick='+datepick+'&datepick2='+datepick2+'&pax_name='+pax_name+'&pax_contact='+pax_contact+'&pax_email='+pax_email;
$.ajax({
type:'POST',
url:'process.php',
data:VarData,
success:function(){
$('#booksuccess').attr('title','Request sent successfully').text('Your request has been sent. We will be in touch soon').dialog({buttons:{'Ok':function(){ $(this).dialog('close');
}},closeOnEscape:true,draggable:false,resizable:false,modal:true});
}
error:function(){
alert('Oops request sending failed. Please try again');
}
});
}
});
});