Grow your CSS skills. Land your dream job.

wordpress custom contact form captcha

  • # April 3, 2013 at 10:49 pm

    I need to add captcha security to a form on my wordpress developed site. Right now works fine but i don’t wanna have any spamming related issue.

    I don’t wanna use the reCaptcha system this is the one i like and been using on other site not developed on wordpress.

    http://www.white-hat-web-design.co.uk/articles/php-captcha.php

    PS: I’m kinda new on wordpress theming.

    this is my code:

    < ?php
    /*
    Template Name: Pagina Contacto
    */

    if(isset($_POST)) {
    if(trim($_POST) === ”) {
    $nameError = ‘Por favor escriba su nombre.';
    $hasError = true;
    } else {
    $name = trim($_POST);
    }

    if(trim($_POST) === ”) {
    $emailError = ‘Por favor escriba su correo.';
    $hasError = true;
    } else if (!preg_match(“/^:alnum:[a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$/i”, trim($_POST))) {
    $emailError = ‘Correo electrónico inválido.';
    $hasError = true;
    } else {
    $email = trim($_POST);
    }

    if(trim($_POST) === ”) {
    $commentError = ‘Please enter a message.';
    $hasError = true;
    } else {
    if(function_exists(‘stripslashes’)) {
    $comments = stripslashes(trim($_POST));
    } else {
    $comments = trim($_POST);
    }
    }

    if(!isset($hasError)) {
    $emailTo = get_option(‘tz_email’);
    if (!isset($emailTo) || ($emailTo == ”) ){
    $emailTo = get_option(‘correocontacto’);
    }
    $subject = ‘[Insigne Studio Español] From ‘.$name;
    $body = “Nombre: $name nnCorreo: $email nnComentario: $comments”;
    $headers = ‘From: ‘.$name.’ < '.$emailTo.'>‘ . “rn” . ‘Reply-To: ‘ . $email;

    wp_mail($emailTo, $subject, $body, $headers);
    $emailSent = true;
    }

    }
    ?>
    < ?php get_header(); ?>

    < ?php if(isset($emailSent) && $emailSent == true) { ?>

    Gracias, su mensaje se ha enviado con éxito.

    < ?php } else { ?>

    < ?php if(isset($hasError) || isset($captchaError)) { ?>

    Lo sentimos pero ocurrió un error. Inténtelo de nuevo.

    < ?php } ?>

    < ?php echo get_post_meta($post->ID, ‘titulo-contacto’, true); ?>

  • Nombre:
  • < ?php } ?>

  • Correo
  • < ?php } ?>

  • < ?php if($commentError != '') { ?>

  • < ?php } ?>


< ?php } ?>

Estamos ubicados en la Ciudad de Playa del Carmen Q.Roo y Cuernavaca Morelos.

< ?php get_footer(); ?>

# April 3, 2013 at 11:32 pm

I’ve used this plugin (http://www.fastsecurecontactform.com/) and it works great.

Note: This is a contact form plugin, and not a captcha plugin, but does have captcha capabilities.

# April 3, 2013 at 11:54 pm

Hi @FragaGeddon i was looking for a handcraft solution, thanks thought i’ll read about it may be handy.

# April 3, 2013 at 11:55 pm

found the solution.

session_start();
if(($_SESSION == $_POST) && (!empty($_SESSION)) ) {
$captcha = trim($_POST);
unset($_SESSION);
} else {
$captchaError = ‘Por favor escriba el código captcha.';
$hasError = true;
}

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".