将自定义验证码添加到备注表单

时间:2015-01-02 作者:Jornes

我的官方网站上有一个博客。我允许人们在我的博客上发表评论,但我不想从自动机器人那里得到评论。因此,我想在评论表单中添加一个称为“安全问题”的额外字段。但我不知道该怎么做。

这是我处理现有联系人表单的代码。(contact\\u info\\u submit.php)

<?php

$name = $_POST[\'name\'];
$phone = $_POST[\'phone\'];
$email = $_POST[\'email\'];
$location = $_POST[\'location\'];
$purpose = $_POST[\'purpose\'];
$status = $_POST[\'status\'];
$findus = $_POST[\'findus\'];
$inquiry = $_POST[\'inquiry\'];
$security = $_POST[\'security\'];
$from = "JT Design";
$to = "inquiry@jtdesign.my";
$subject = "$from, $name has submitted the enquiry form.";
$message = "Hi $from,\\n$name has submitted the enquiry form. Details are as follow: \\n\\n/*** Form Details Begin ***/\\n\\nName: $name\\nPhone Number: $phone\\nEmail Address: $email\\nLocation: $location\\nContact Purpose: $purpose\\nHouse Status: $status\\nHow did visitor find us?: $findus\\nMessage: $inquiry\\n\\n/*** Form Details Ended ***/\\n\\nPlease response to $name as soon as possible.\\n\\nRegards,\\n$from";

if ($security=="17") {
   mail($to, $subject, $message, "From: JTDesiGn");
   header("Location:/thanks.php");
}

else {
   header("Location:/enquiry-form/?Submission=failed");
}
?>
查看我的在线咨询表单的Url:www.jtdesign.my/enquiry-form/

有什么解决方案可以将此代码应用于wordpress评论表单?我只想添加“安全”字段。

2 个回复
SO网友:nkuldip

使用此SI CAPTCHA反垃圾邮件插件,可能对您有所帮助

https://wordpress.org/plugins/si-captcha-for-wordpress/screenshots/

SO网友:nkuldip

这是exmaple代码,您可以根据需要进行更改

把这个放进你的HTML

<INPUT class="input" type="text" name="vercode" value="" required>                                     
<img src="captcha.php" style="margin:3px 0px; width:110px; height:34px">
创建Captcha文件captcha.php

<?php 
session_start(); 
$text = rand(10000,99999); 
$_SESSION["vercode"] = $text; 

$image = imagecreatefromjpeg("images/bg.jpg");
$txtColor = imagecolorallocate($image, 0, 0, 0);
imagestring($image, 5, 5, 5, $text, $txtColor);
header("Content-type: image/jpeg");
imagejpeg($image);
?>
然后使用此代码

<?php 
session_start(); 
if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]==\'\')  { 

     echo  \'<strong>Incorrect verification code...</strong>\'; 
}
else
{
    $name = $_POST[\'name\'];
$phone = $_POST[\'phone\'];
$email = $_POST[\'email\'];
$location = $_POST[\'location\'];
$purpose = $_POST[\'purpose\'];
$status = $_POST[\'status\'];
$findus = $_POST[\'findus\'];
$inquiry = $_POST[\'inquiry\'];
$from = "JT Design";
$to = "inquiry@jtdesign.my";
$subject = "$from, $name has submitted the enquiry form.";
$message = "Hi $from,\\n$name has submitted the enquiry form. Details are as follow: \\n\\n/*** Form Details Begin ***/\\n\\nName: $name\\nPhone Number: $phone\\nEmail Address: $email\\nLocation: $location\\nContact Purpose: $purpose\\nHouse Status: $status\\nHow did visitor find us?: $findus\\nMessage: $inquiry\\n\\n/*** Form Details Ended ***/\\n\\nPlease response to $name as soon as possible.\\n\\nRegards,\\n$from";

if ($security=="17") {
   mail($to, $subject, $message, "From: JTDesiGn");
   header("Location:/thanks.php");
}

else {
   header("Location:/enquiry-form/?Submission=failed");
}
}
?>

结束

相关推荐