3
我对创建的联系表单有两个问题。我之前受到垃圾邮件的严重打击。表单验证和验证码
我要求所有字段的形式被处理之前填写,但我已经写不工作:信息进入数据库中的人是否填写所有字段与否。 ***通过使用固定:
function validateForm() { var x = document.forms [“validation”] [“firstname”] .value; if(x == null || x ==“”) { alert(“请输入您的名字”); 返回false; }
所有字段和一个电子邮件:
var x=document.forms["validation"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Please enter a valid email address");
return false;
}
现在,我需要验证码的工作或如何添加检查验证码是相同的JavaScript是否正确?我认为错误在于这个不知何故?:
session_start();
if($_POST['submitted'] == "contactus")
if($_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'])) {
header("Location:http://www.berrieswebdesign.com/thankyou.php?message=thanks");
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo "<div id='thankyoubox'>'Security breach! Security Breach! Ehem...Your security code was incorrect.'</div>";
}
ob_flush();
?>
最后,这里是contactfunctions.php
<?php ob_start();//Required for the redirect to work?>
<?php
include_once("databasefunctions.php");
$contactsdbtable = "contacts";
function GetHeaders()
{
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "To: {$firstname} <{$email}>" . "\r\n";
$headers .= 'From: My Website <[email protected]>' . "\r\n";
return $headers;
}
function ContactMessage($firstname, $lastname, $email, $message, $location)
{
global $contactsdbtable;
openDatabase();
$firstname = mysql_real_escape_string($firstname);
$lastname = mysql_real_escape_string($lastname);
$email = mysql_real_escape_string($email);
$message = mysql_real_escape_string($message);
$location = mysql_real_escape_string($location);
$result = QuickQuery("INSERT INTO {$contactsdbtable}(firstname, lastname, email, message, location)
VALUES('{$firstname}', '{$lastname}', '{$email}', '{$message}', '{$location}')");
if($result)
{
$headers = GetHeaders();
$message = "\"Thank you for contacting us at My Website. We will be answering your website inquiry post haste.\"<br />
<br />
<br />
Best Regards,<br />
<br />
Me
";
mail($email, "RE: Design Inquiry", $message, $headers);
mail("[email protected]", "Website Inquiry", "{$firstname}, {$email}, has sent a web design inquiry", $headers);
}
}
?>
我感激我得到这个提前任何帮助。另外,由于这是一篇冗长的文章,你们能介绍一下你正在处理的问题,1或2吗?
谢谢!
感谢扎克。我尝试了这一点,并跳过添加信息到一个表单域,但其余的信息仍然进入数据库 – user1505573 2012-07-31 17:21:01
谢谢扎克。还是行不通。我现在已经实现了JavaScript(礼貌w3学校),当字段没有填写时发出警报。我已经测试过它,并且在填写所有字段之前没有任何内容进入数据库。但我仍然有验证码问题。请参阅上面的修订代码。 – user1505573 2012-07-31 17:42:14
上面的编辑应该修复验证码问题 – Zac 2012-07-31 18:01:04