Custom Contact Forms
[resolved] SPAM prevention with Recaptcha (5 posts)

  1. aschmutt
    Posted 4 years ago #


    the current Captcha is not working.
    You write the captcha code in the session - and spambot can read the session data.

    This code can be used to include Recaptcha instead.
    You have to do these changes in custom-contact-forms-front.php:

    function getCaptchaCode($field_object, $form_id) {
    /*replace HTML Output in $out:
    $out = '<img width="96" height="24" alt="' . __('Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image', 'custom-contact-forms') . '" id="captcha-image" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/custom-contact-forms/image.php?fid='.$form_id.'"'.$code_type.'>
    <div><label for="captcha'.$form_id.'">* '.$field_object->field_label.'</label> <input class="'.$field_object->field_class.' '.$tooltip_class.'" type="text" '.$instructions.' name="captcha" id="captcha'.$form_id.'" maxlength="20"'.$code_type.'></div>';
    return $out;*/
    $publickey = "your_key"; // you got this from recaptcha.org
    $out = '<div><label for="captcha'.$form_id.'">* '.$field_object->field_label.'</label></div>';
    $out .= recaptcha_get_html($publickey);
    return $out;

    Then find elseif ($field->field_slug == 'captcha') {
    and replace the else code with recaptcha validation:

    elseif ($field->field_slug == 'captcha') {
    $privatekey = "your_private_key";
    $resp = recaptcha_check_answer ($privatekey,
    if (!$resp->is_valid) {
    if (empty($field->field_error))
    	$this->setFormError('captcha', __('You copied the number from the captcha field incorrectly.', 'custom-contact-forms'));
    else $this->setFormError('captcha', $field->field_error);

    Don't forget to upload recaptchalib.php where require_once can find it.



  2. norsewulf
    Posted 4 years ago #

    Thanks for posting this Andrea. I'm having trouble getting it working though.

    I believe I followed your instructions correctly, but my page isn't loading now... Any thoughts? Did anyone else get this working properly?

  3. norsewulf
    Posted 4 years ago #

    Also I did have the wp-recaptcha plugin installed and activated. I think there is a possibility this may have been part of the problem. When I de-activated the plugin the page would load, but there still wasn't any reCaptcha on the page.

  4. UnniKris
    Posted 4 years ago #

    Thanks for the post Andrea.

    I was able to display the recaptcha in the form. But when i am submitting the form, i am getting an error : Could not open socket.

    When i debugged the code i found that the error was due to : php_network_getaddresses: getaddrinfo failed.

    Please help, what i need to remove this error?

  5. Atlanta
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Contact Forms
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic