First, I don't know if I chose the right title, so I'll explain. My website receive many spam comments, so to combat the spam, I added a hidden input into my comment.php (wordpress) form - its about comment form not contact or else form. The HTML:
<input type="text" name="url" id="url" value="'. $comment_author_url .'" size="44" tabindex="3" />
<span class="error"><?php echo $urlErr; ?></span>
CSS:
input[type="text"]#url { display: none; }
At the beginning, to block bots for posting comments I add a jquery code. Its worked ok but I still receive spam-comments. I read on the internet that these bots have javascript disabled so my method is pointless.
So I tried to use php... The first code I tried
$url_error = '';
$urlErr = '';
if($_REQUEST['submit']){
if(trim($_REQUEST['url'] !== "")){
$urlErr = "Go away";
}else {
$url = trim($_REQUEST['url']);
}
}
With this php code if the bot will fill the hiddent input url then it will not submit a comment. But the code didn't work.
I tried another code from w3school:
$urlErr = "";
$url = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST["url"])) {
$urlErr = "Go away";
} else {
$url = test_input($_POST["url"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
But also didn't work. So What I'm doing wrong? :( I need to make it work with php... its very interesting method to block spammers.