0
我已經使用JavaScript來驗證窗體使用ID #mycontactform,但它不工作。 然後我用過,但它也不起作用。我花了更多的時間在這方面,但仍然沒有取得成功。驗證不在電子郵件模板中工作
這是我試過的JavaScript。
$(document).ready(function() {
//$('#mycontactform').submit()
$('#mycontactform').submit(function() {
$.post('send.php', $('#mycontactform').serialize(), function(response) {
$('#success').html(response);
//$('#success').hide('slow');
setTimeout(function() {
alert('Information Send Successfully');
}, 1000);
$('#submit').css('background','green');
});
return false;
});
});
這裏是HTML:
<form id='mycontactform' action='send.php' method='post'>
<select id='time' name='time' style='text-align:center;' required>
<option value=''> -- select -- </option>
<option value='this week'>this week</option>
<option value='next week'>next week</option>
<option value='no rush'>no rush</option>
</select>
<select id='people' name='people' style='text-align:center;' required>
<option value=''> -- select -- </option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
<label for='radio3'>Yes</label>
<input type='radio' id='radio3' name='obstacles' value='yes' checked>
<label for='radio4'>No</label>
<input type='radio' id='radio4' name='obstacles' value='no'>
</form>
這裏是PHP:
<?php
$obstacles = $_POST['obstacles'];
$people = $_POST['people'];
$tim = $_POST['time'];
$to = '[email protected]';
$from = $email;
$subject = 'Domestic & Commercial Gutter cleaning Replies From Email';
$body = "Obstacles : <strong>$obstacles</strong><br>
People Required : <strong>$people</strong><br>
Time required : <strong>$tim</strong><br>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from";
$ok = mail($to, $subject, $body, $headers);
if($ok)
echo '1';
else
echo '0';
?>
請建議我有幫助的解決方案。所有可能的方式,如使用Ajax,使JavaScript工作,或任何其他方式。
你能顯示您的JavaScript代碼? – putvande
你是否確實阻止了你的javascript代碼提交表單,所以你可以先檢查? – rita
我剛剛使用HTML 5驗證,它是「必需的」,它工作正常,但在gmail中得到它後,它無法工作。 – kds7ap