Hi all,
I'm trying to use the Akismet PHP5 plugin to stop spam being sent through my contact forms. The forms being on a standard PHP page and not in WordPress or anything else. I'm struggling to understand how exactly to implement it on other fields than the ones provided in the Akismet class file. Below is my code (left out API key etc on purpose), however am unsure if i'm supposed to use setCommentContent for all input fields which are not either author, email, url or comment?
Also unsure of how I can really test this, e.g. what would be classed as spam to input into the form to check? I've done stuff in procedural PHP, so by just be my lacking in OOPHP. Any advice would be appreciated.
<?php
require_once ('classes/Akismet.class.php');
$akismet = new Akismet( "http://mywebsite.com", "API KEY HERE");
// checks if key is valid
if($akismet->isKeyValid()) {
// api key is okay
} else {
// api key is invalid
}
if (isset($_POST['submit'])) {
// assign variable
$_POST['name'] = $name;
$_POST['department'] = $department;
$_POST['url'] = $url;
$_POST['email'] = $email;
$_POST['telephone'] = $telephone;
$_POST['comment1'] = $comment1;
$_POST['comment2'] = $comment2;
$akismet->setCommentType("enquiry");
$akismet->setCommentAuthor( $name );
$akismet->setCommentContent( $department );
$akismet->setCommentAuthorURL( $url );
$akismet->setCommentAuthorEmail( $email );
$akismet->setCommentContent( $telephone );
$akismet->setCommentContent( $comment1 );
$akismet->setCommentContent( $comment2 );
if( $akismet->isCommentSpam() )
{
echo 'This email contains spam!';
}
else
{
echo 'All looks okay here, send data to mailbox';
// add send to email info here.
}
}
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-GB">
<head>
<meta charset="UTF-8" />
<title></title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0" />
<meta name="description" content="" />
<link rel="stylesheet" href="css/style.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<main role="main">
<form action="" method="post">
<ul>
<li>
<label for="name">Name</label>
<input type="text" id="name" name="name" value="" />
</li>
<li>
<label for="department">Department</label>
<input type="text" id="department" name="department" value="" />
</li>
<li>
<label for="url">URL</label>
<input type="text" id="url" name="url" value="" />
</li>
<li>
<label for="email">Email</label>
<input type="text" id="email" name="email" value="" />
</li>
<li>
<label for="telephone">Telephone</label>
<input type="text" id="telephone" name="telephone" value="" />
</li>
<li>
<label for="comment1">Comment 1</label>
<textarea id="comment1" name="comment1" cols="20" rows="4"></textarea>
</li>
<li>
<label for="comment2">Comment 2</label>
<textarea id="comment2" name="comment2" cols="20" rows="4"></textarea>
</li>
<li>
<input type="submit" name="submit" value="Submit" />
</li>
</form>
</main>
</body>
</html>
Thanks.