SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Capcha & form

  1. #1
    SitePoint Enthusiast ndtoan13's Avatar
    Join Date
    Dec 2004
    Location
    VietNam
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Capcha & form

    I make a capcha myself to prevent user from posting spam. I have also made an option for them to see another code if it is hard to see the image.
    The problem is : when user enter wrong code it tell user that the code is wrong (by javascript alert) then return to the form, now user have to enter all information he has entered!! How to avoid this (I mean user should not need to re-enter all information)?

    Thank you.

  2. #2
    SitePoint Evangelist praetor's Avatar
    Join Date
    Aug 2005
    Posts
    479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You repopulate the correct fields with the values from $_POST.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Location
    GR
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why reload the page if you are doing it from javascript.
    You can do this on a input field
    <input type="text" name="username" value="<? if isset($_POST['username']) echo $_POST['username']; ?>" />

  4. #4
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe i'm misunderstanding but if you're using javascript to check the fields why is a different page being loaded?

    Also is there any particular reason to check for $_POST variables before echoing them in inputs. Why not just echo $_POST['var'], if it isn't set it won't echo anything. Just curious.

  5. #5
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    You could get rid of the CAPTCHA altogether and replace it with a form field that sits inside of a hidden div. If the field gets filled out, you have spam. If not, it's valid.

  6. #6
    SitePoint Enthusiast ndtoan13's Avatar
    Join Date
    Dec 2004
    Location
    VietNam
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for all help.
    I put the secure image in a <IMG> tag.
    <img id="sec_code" src="<?php echo $securelink;?>" border="0" title="<?php echo _SEC_CODE; ?>" alt="<?php echo _SEC_CODE; ?>" />
    Where $securelink is an instant of a class that render the image randomly.
    And the value is store in senssion, so I can not check it through javascript.
    $simg = new simg();
    $_SESSION['seccode'] = $simg->getsnum();
    @ _Steve_ : I will try to get $_POST value, does it cause troulble if i do that
    Also is there any particular reason to check for $_POST variables before echoing them in inputs
    @ Hartmann : could you tell me more in detail about your idea
    You could get rid of the CAPTCHA altogether and replace it with a form field that sits inside of a hidden div. If the field gets filled out, you have spam. If not, it's valid.

  7. #7
    SitePoint Enthusiast ndtoan13's Avatar
    Join Date
    Dec 2004
    Location
    VietNam
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use javascipt to go back
    if($scheck != $seccode){
    echo "<script> alert('"._MCAL_ITEM_SEC_CODE_WRONG."'); history.back();</script>\n";
    exit();
    }
    But when I come back, I can not get the $_POST value!

    Any idea?

  8. #8
    SitePoint Enthusiast ndtoan13's Avatar
    Join Date
    Dec 2004
    Location
    VietNam
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found solution myself
    remove history.back(); then call showform function; replace exit(); with return;


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
  •