我知道這個問題已經被問了很多,但沒有一個解決方案適用於我!
請先閱讀下面的編輯!
我是比較新的PHP和我創建一個簡單的聯繫形式:
HTML:
<form action="contactUsSuccess.php" id="contactForm" method="post" name="contactForm" onsubmit="return validateContactUs();">
<table>
<tr>
<td>
<input id="name" maxlength="70" name="name" placeholder="Name" type="text">
</td>
<td>
<input id="email" maxlength="255" name="email" placeholder="Email" type="text">
</td>
</tr>
<tr>
<td colspan="2">
<textarea id="message" maxlength="5000" name="message" placeholder="Message"></textarea>
</td>
</tr>
<tr>
<td colspan="2" id="submitArea">
<input id="submitButton" type="submit" value="Send">
</td>
</tr>
</table>
</form>
PHP,這是另一頁。
<?php
$success = false;
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$to = "[email protected]";
$subject = "New Contact Message - ----";
$messageMail = "From: " . $name . "(" . $email . ")" . " | Message: " . $message;
$header = "From: [email protected]";
if(mail($to, $subject, $messageMail, $header)) {
$success = true;
}
?>
我的錯誤:
Notice: Undefined index: name in Z:\Documents\Workspace\----\help\contactUsSuccess.php on line 6
Notice: Undefined index: email in Z:\Documents\Workspace\----\help\contactUsSuccess.php on line 7
Notice: Undefined index: message in Z:\Documents\Workspace\----\help\contactUsSuccess.php on line 8
正如你或許可以看到,我的窗體的onsubmit
執行JavaScript的,剛剛返回true或false。如果你出於任何原因認爲這可能是不工作的原因,請問。
而且,我已經試過了上面顯示的相同的PHP代碼,並把它放在同一個文件中的原始HTML(並且還與isset
周圍的if語句...沒有運氣。
哦,和電子郵件仍然發送...它只是發送:
From:() | Message:
編輯:所以這是JavaScript的下面是它的主要部分:
if (!(nameLen > 0 && nameLen <= 70 && emailLen > 0 && emailLen <= 255 && messageLen > 0 && messageLen <= 5000)) {
cont = false;
} else {
name.disabled = "true";
email.disabled = "true";
message.disabled = "true";
document.getElementById("submitButton").disabled = "true";
}
if (cont) {
return true;
} else {
return false;
}
}
當我刪除了3 --.disabled = "true";
,它工作!不過,我確實有他們的原因。有其他選擇嗎?我想這是我要問現在...
請問當你把它的工作提交事件中的驗證功能? (即,JavaScript) –
您需要首先檢查是否設置了post變量的天氣 –
您確定在所有$ _POST變量中使用了isset方法嗎? –