0
我在我的網站上有一些非常基本的PHP驗證代碼,它已經工作了一段時間。我不是任何方式的PHP專家(顯然下面我肯定):),但此代碼工作正常,我的需要,直到現在...我最近意識到這段代碼已停止工作,我不知道爲什麼。任何幫助,將不勝感激。我想可能是服務器上發生了一些變化,所以我和我的主機公司聊了聊,他們向我保證沒有任何變化,並且必須是代碼錯誤。PHP表單驗證代碼用於正常工作,停止工作,我不知道爲什麼
這裏是代碼的基本部分:
<?php // Handle the form submission
// VALIDATE Forms Required Fileds
//Check for name.
if (strlen($_POST['name']) > 0){
$name = $name;
} else {
$name = NULL;
}
//Check email was entered
if (strlen($_POST['email'])=='') {
$email = NULL;
} elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) {
$email = "invalid";
} else {
$email = $email;
}
// END VALIDATION
// If all is ok then handle form
if ((isset($_POST['Submit']) || isset($_POST['Submit_x'])) && ($name && $email && $email != "invalid"))
{
// Capture information and format for email
$subject="Side Nav Form"; // Subject of Email
$body = "Contact Us:\n\n";
$body .="Name..............: " ."$name\n";
$body .="Email.............: " ."$email\n";
$body .="Phone.............: " ."$phone\n\n";
$body .="Reason for inquiry: " ."$inquiryReason1, $inquiryReason2, $inquiryReason3\n";
$body .="Current Website...: " ."$current_site\n\n";
$body .="Comments/Questions: " ."$addtlComments\n";
//Email form results
mail("[email protected]", $subject, $body, "From:" .$email);
// Display thank you Message if form submitted successfully.
echo '<h3>Thank you!</h3><p>We received your information and will get back to you as soon as possible.</p>';
} else {
// If Validating form: Show validation errors.
if ((isset($_POST['Submit']) || isset($_POST['Submit_x'])) && (!$name || !$email || $email == "invalid")) {
echo '<p class="error">';
if (!$name) {
echo "*Please enter your name.<br />";
}
if (!$email) {
echo "*Please enter your email address.<br />";
}
if ($email == "invalid") {
echo "*Please enter a valid email address. ([email protected])";
}
echo '</p>';
}
// Display the form if user has not submitted successfully or at all.
?>
<fieldset><label for="name">*Name:</label> <input type="text" name="name" id="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" /></fieldset>
<fieldset><label for="email">*Email:</label> <input type="text" name="email" id="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></fieldset>
... rest of form fields...
<input name="Submit" type="submit" value="Submit" class="submit" />
</form>
<?php
} // End of Form Handler
?>
'停止工作,我不知道爲什麼',我們也沒有。你收到什麼錯誤信息? – 2012-02-13 19:29:25
什麼錯誤提交給你? – 2012-02-13 19:29:33
在黑暗中拍攝:您的服務器的php版本已更改爲5.3。*和E_STRICT錯誤在全地飛來飛去? – CBusBus 2012-02-13 19:33:51