和當你點擊發送一個彈出窗口出現,說它是否已成功發送。多數民衆贊成所有我想要發生,但在此刻彈出窗口出現,並在用戶按下的窗口發送它到php頁面的動作調用,我如何停止該窗口去php頁面,只是有一個彈出窗口出現?住在同一頁上後
表單代碼:
<form method="post" class="contact-form" action="php/callback.php" >
<input name="name" type="text" id="formbox" value="Name" onfocus="(this.value == 'Name') && (this.value = '')" onblur="(this.value == '') && (this.value = 'Name')"/><br />
<input name="number" type="text" id="formbox" value="Number" onfocus="(this.value == 'Number') && (this.value = '')" onblur="(this.value == '') && (this.value = 'Number')"/><br />
<input type="submit" value="Send" id="formbutton">
</form>
PHP代碼:
<?php
$name = $_POST['name'];
$number = $_POST['number'];
$to = "[email protected]";
$subject = "Call Back Enquiry";
$message = "Hi Raymond, someone that came to your website wants you to call them back, their name is '$name' and their number is '$number'";
$from = "Your Website";
$headers = "From:" . $from;
$send_contact = mail($to,$subject,$message,$headers);
if($send_contact){
echo "<script>alert('We will contact you shortly');</script>";
}
else {
echo "<script>alert('Something went wrong, try again!');</script>";
}
?>
你需要javascript/ajax,你不能單獨使用php。 – jeroen 2013-03-06 14:56:36
這裏看看http://stackoverflow.com/questions/425095/submit-form-using-ajax-and-jquery – karmafunk 2013-03-06 14:57:47