0
(我沒有意識到我之前已經制作的貼子可以編輯並重新打開,對此過程感到困惑......)爲什麼我的提交表單將我帶到我的php頁面?
當我點擊發送表單時,我發送到我的PHP頁面顯示數字0.我不明白爲什麼會發生這種情況。這裏的(大部分)全碼:
<form id="contactForm" method="post" action="js/formCheck.php">
<div class="formCol">
<label>Email:</label>
<input type="email" id="formEmail" name="email" autocomplete="off" placeholder="Your email address..." required/>
</div>
<div class="formCol midCol">
<label id="floatMsg">Message (350 chars):</label>
<textarea id="formMessage" name="message" rows="5" cols="40" maxlength="350" placeholder="What have you got to say?" required></textarea>
</div>
<div class="formCol lastCol">
<input type="submit" class="submit-btn" name="submit" value="Send" />
</div>
</form>
...腳本
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!--[if lt IE 9]><script src="js/modernizr.custom.js"></script><![endif]-->
<script src="js/jquery.flexslider-min.js"></script>
<script src="js/functions.js"></script>
<script>
$(document).ready(function() {
$('#form').ajaxForm(function() {
alert("Thank you for your comment! I will receive it shortly and get back to you as soon as possible.");
document.getElementById("form").reset();
});
});
</script>
發送電子郵件(PHP)
if (isset($_POST['submit'])) {
$email = htmlspecialchars($_POST['email']);
$comment = htmlspecialchars($_POST['message']);
/* Sending Email */
$from_add = "Visitor";
$to_add = "[email protected]";
$subject = "The_Message_Subject";
$message = "
Message Information
Email = $email
Message = $comment";
$headers = "From: $from_add \r\n";
$headers .= "Reply-To: $from_add \r\n";
$headers .= "Return-Path: $from_add \r\n";
$headers .= "X-Mailer: PHP \r\n";
mail($to_add, $subject, $message, $headers);
}
在你的表單上'action =「js/formCheck.php」'這是php對嗎? – ianace 2013-03-02 02:46:56
document.getElementById(「form」)在你的元素中沒有聲明'form'id。 – Snippet 2013-03-02 02:49:57
編輯原始問題,不要問兩次。 – 2013-03-02 02:54:37