Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have several inputboxes and no textareas in my custom content type. Can I use Akismet that comes with WP for that? If I can, how to do that?

E.g. If I have 5 inputboxes like: name, address, city, telephone, email in my form that is saved from the front page and is used for further processing.

How to use Akismet on that? Is it possible?

if the names of the inputbosex are: name, address, city, telephone and emai, how would you set up the Akismet plugin. What should be done so no spams are saved in my db? (I need to filter the data before being saved to data using akismet in my function in functions.php. So if I get the values like e.g.

$name = $_POST['name'];
$name = $_POST['address'];
$name = $_POST['city'];
$name = $_POST['telephone'];
$name = $_POST['email'];

// here I need if condition to use akismet database to redirect back to the post without executing the rest of my code in my function.

How to do such condition using the Akismet plugin that comes with Wordpress?

share|improve this question

2 Answers 2

Akismet - libraries:

First I want to mention that there are many Akismet libraries out there:

http://akismet.com/development/

and here are the API documents:

http://akismet.com/development/api/

Akismet - WordPress plugin:

But as I understand it, you want to use the Akismet WordPress plugin as your library.

The following code snippet is a simple proof of concept, based on the Akismet plugin:

// We assume that Akismet is installed with the corresponding API key
if( function_exists( 'akismet_http_post' ) )
{   
    global $akismet_api_host, $akismet_api_port;

    // data package to be delivered to Akismet (Modify this to your needs)
    $data = array( 
        'comment_author'        => 'Mr. Spam',
        'comment_author_email'  => 'mr.spam@ispamalot.com',
        'comment_author_url'    => 'spamalot.com',
        'comment_content'       => 'Hello Spam World!',
        'user_ip'               => '123.123.123.123',
        'user_agent'            => '',
        'referrer'              => '',
        'blog'                  => 'http://example.com',
        'blog_lang'             => 'en_US',
        'blog_charset'          => 'UTF-8',
        'permalink'             => 'http://example.com/hello-world',
        'is_test'               => TRUE,
    );

    // construct the query string
    $query_string = http_build_query( $data );
    // post it to Akismet
    $response = akismet_http_post( $query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
    // check the results        
    $result = ( is_array( $response ) && isset( $response[1] ) ) ? $response[1] : 'false';
    // display the result (it can be 'true', 'false' or some error message )    
    printf( 'Is it spam? Akismet says: %s', $result );
}

where I use the akismet_http_post function to post the data to the Akismet servers.

According to the API docs, the following parameters are required:

blog, user_ip, user_agent

and one should be careful regarding the spelling of the referrer parameter ;-)

Other useful Akismet functions are for example:

- akismet_get_key()
- akismet_check_key_status()
- akismet_verify_key()

The response I got when testing a real spam comment, was like this:

Array
(
    [0] => Array
        (
            [server] => nginx
            [date] => Wed, 23 Oct 2013 12:44:37 GMT
            [content-type] => text/plain; charset=utf-8
            [content-length] => 4
            [connection] => close
            [x-akismet-server] => 192.0.80.244
            [x-akismet-guid] => 07d0136b53cda37432ff5a7b6d86c843
        )

    [1] => true
)

with the positive (true) spam result.

The next step would be to modify this into a usable function or a class.

Since you're using some custom form fields, I think you could map them like this:

name                       --> comment_author
email                      --> comment_author_email
address + city + telephone --> comment_content
share|improve this answer

I don't think that akismet is the right tool for you. The way akismet works relies on analyzing the content of millions of comments and detect spamming patterns, but the content of your form is not similar to comments and therefor the analyze will be worthless. The only thing akismet can do with you code is to check for known samming IP addresses, something that you can do with other services like the honeypot project which might be a better alternative since you need to pay for using akismet on any commercial site. Remember that with akismet you also need to decide what do you do when it flags something as spam. The default behavior of the plugin is to keep the comments in the DB in order for a human to be able to check them for false positives. To mimic that you will need to keep your forms in the DB as well even if they where flagged as sam but you will need to develop new UI for it.

There is a simpler solution which might be even more effective then using akismet, just use JS to inject an hidden input with a known value to the form and validate the value when handling the submition on the server side. if validation fails then the form is probably spam. If you are worried about people that don't use JS not being able to send the form, you can always add a notice that JS should be enabled to send the form to your form, and hide it in JS. Most spambots right now don't parse and execute JS therefor this should be a very good way to stop spam.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.