SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cathpa validation problem

    Hi,

    I'm hoping to get some help with some PHP code I'm having trouble with on my contact form page...

    Please see the below quoted text from a conversation I've just had with someone in the Javacsript forum who helped with fixing the Javascript validation for my contact form, to see the PHP problem I need help with, thanks.


    Exactly, just copy and paste this:

    Code JavaScript:
    function validateForm(){
    var errorMessage="";
    var name=document.forms["contact"]["txtName"].value;
    var email=document.forms["contact"]["txtEmail"].value;
    var input=document.forms["contact"]["txtInput"].value;
    var atpos=email.indexOf("@");
    var dotpos=email.lastIndexOf(".");
    if (name==null || name==""){
    errorMessage = "Your Name is required.\n";
    }

    if (email==null || email==""){
    errorMessage += "Email address is required.\n";
    } else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length){
    errorMessage += "Please enter a valid email address.\n";
    }

    if (input==null || input==""){
    errorMessage += "Captcha code is required.\n";
    }

    if (errorMessage !=""){
    alert(errorMessage);
    return false;
    }
    }

    Excellent, that worked, thanks very much.

    One other thing remains to fix, the catchpa code submits even if the wrong code is submitted, I have copy and pasted the following PHP code form the original page on which I have the catchpa code into the contact page head section , but it's not working, any chance you would be able to help with this, or is it better to post this in another section of the forums?

    PHP
    Code:
    <?php

    if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['txtInput']) != 0)

    {

    //Note: the captcha code is compared case insensitively.

    //if you want case sensitive match, update the check above to

    // strcmp()

    $errors .= "The captcha code does not match";

    }
    ?>
    If more information is needed, my original post in the Javascript forum, which notes more code, is here: http://www.sitepoint.com/forums/show...on-not-working

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,901
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Quote Originally Posted by daniela View Post
    I'm hoping to get some help with some PHP code I'm having trouble with on my contact form page...
    Where do you have the captcha code from?
    Is it something you wrote yourself or is it a script you have from somewhere?

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2003
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I copy and pasted the catchpa code into the contact form from another page on my site (http://www.ready2rock.com.au/booknow.php), which a programmer coded for me.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,901
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Ah, ok.
    Is it important to you to have the same style of captcha image on your new page, or would you be fine with using another captcha script from somewhere else?

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2003
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any catchpa code is fine.

  6. #6
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,901
    Mentioned
    212 Post(s)
    Tagged
    12 Thread(s)
    Ok, well basically you have two options.

    1. You could use one of the many Captcha services out there. They are free and easy to set up. Recaptcha is probably the most well known: http://www.google.com/recaptcha, or you could just peruse this list: http://www.netwaver.com/35/34-free-c...spam-services/
    2. I just dug a simple Captcha script out of my snippets archive. I could let you have this if you like and help you integrate it into your page. So that you can see what the end product is like, I've made a quick demo page here: http://hibbard.eu/blog/pages/captcha/
    Please bear in mind however, that these Captchas present some people with quite a usability barrier (my parents for example have real trouble filling them out), so if I was you, I would opt for a service like Recaptcha (which at least gives you the possibility of listening to what is being displayed).

    HTH

    Edit: Of course we could also try and re-implement your current Captcha system on your new page. For this to work you would have to provide the code which is used to generate the image, the code used to include the generated image in your form and also the code to evaluate whether or not the correct code was entered.

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2003
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will have a look at recaptcha and I will probably integrate that into my contact form. Thanks very much for your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •