<script language="JavaScript" src="gen_validatorv4.js" type="text/javascript"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div id="contactform">
<div id="details">
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Full name *:</label><br>
<input type="text" name="name">
</p>
<p>
<label for='address'>Address *:</label><br>
<input type="text" name="address">
</p>
<p>
<label for='unit'>Unit:</label><br>
<input type="text" name="unit">
</p>
<p>
<label for='postal'>Postal code *:</label><br>
<input type="text" name="postal">
</p>
<p>
<label for='email'>Email:</label> <br>
<input type="text" name="email">
</p>
<p>
<label for='phone'>Telephone *:</label><br>
<input type="text" name="phone">
</p>
<p>
<label for='date'>Preferred pickup date* :</label> <br>
<input type="date" name="date">
</p>
<p>
<label for='time'>Preferred timeslot* :</label><br>
<span id="small">Please provide us with a 2 Hr time slot<br> (10% discount if we don't make it in time <strong>after we agreed</strong> on a timeslot</span><br>
<input type="text" name="time1"> to <input type="text" name="time2">
</p>
</div>
<div id="products">
<p><label for='itemsharp'>Items for sharpening:</label><br>
<textarea name="itemsharp"></textarea>
</p>
<p>
<label for='itemrepair'>Items for repair:</label><br>
<textarea name="itemrepair"></textarea>
</p>
<p>
<label for='comment'>Comment: </label><br>
<textarea name="comment"></textarea>
</p>
<div class="g-recaptcha" data-sitekey="[mysitekey]" data-theme="dark"></div>
<input class="button" type="submit" value="Submit"><br>
</form>
</div>
</div>
的PHP:
<?php
$errors = '';
$myemail = '[aperfectlyvalidemailadress]';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['address']) ||
empty($_POST['postal']) ||
empty($_POST['date']) ||
empty($_POST['time1']) ||
empty($_POST['time2']) ||
empty($_POST['phone']))
{
$errors .= "\n Error: fields with a * are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$address = $_POST['address'];
$postal = $_POST['postal'];
if(!empty($_POST['unit'])){
$unit = $_POST['unit'];
}
$phone = $_POST['phone'];
$date = $_POST['date'];
$time1 = $_POST['time1'];
$time2 = $_POST['time2'];
$itemsharp = $_POST['itemsharp'];
$itemrepair = $_POST['itemrepair'];
$comment = $_POST['comment'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Please provide a valid email address";
}
$captcha;
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the captcha form.</h2>';
exit;
}
$secretKey = "[mysecretkeyisfilledinhere]";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the @$%K out</h2>';
} else {
if(empty($errors))
{
$to = $myemail;
$email_subject = "Sharpening request: $name";
$email_body = "You have received a new sharpening request. ".
"From:\n Name: $name \n Email: $email_address \n Phone: $phone \n Address: $address $unit $postal \n \n Date: $date \n Between: $time1 and $time2 \n Items for sharpening: $itemsharp \n Items for repair: $itemrepair \n Comment: \n $comment ";
$headers = "From: [email protected]\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: requestthankyou.html');
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Request failed</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
大部分是從各種來源拼湊。我的PHP不是那麼強大。
我在第一次創建它時測試了它,它工作正常。
現在,該網站是生活和....沒有。任何嘗試提交表單都會導致「請檢查驗證碼」錯誤頁面。我沒有改變一件事,這就是爲什麼我感到沮喪。
由於顯而易見的原因,我在此屏蔽了電子郵件地址和密鑰。
我已經看過其他問題,但他們要麼不相關(使用不同的和不熟悉我的語言),或者我根本不明白我爲此道歉。
任何幫助將不勝感激。
您是否在控制檯中看到任何錯誤?是否所有的文件加載好(再次,在網絡控制檯尋找404錯誤) – RamRaider
我可以看到你的窗體中的一些任性的HTML標記〜你在表單內部和周圍使用div標籤的方式使得它無效narkup – RamRaider
@RamRaider沒有404錯誤。我同意div標籤很奇怪,但它們是用於定位的目的。我想要兩列,而不是一個長的形式。 – Ehlyah