Jump to content

CAPTCHA Issues


kyleldi

Recommended Posts

Hi Everyone,

 

So i'm working on this captcha script- using recaptcha, and it doesn't seem to make any difference if the input information is correct or not, yet it still posts the form.  Here's the code, can anyone see what i'm doing wrong?  The script (recaptcha) works fine if i don't use it integrated into my form- so I know it's actually working.

 

Any help is much appreciated :)

 

    <div class="quoteform">
      <form action="" method="post" enctype="multipart/form-data" name="form" class="forms" id="form">
        <table width="100%" border="0">
          <tr>
            <td width="30%"> </td>
            <td width="70%"><input name="date" type="hidden" id="date" value="<?php print date("F d, Y"); ?>" /></td>
          </tr>
          <tr>
            <td>Company Name:</td>
            <td><input name="company" type="text" id="company" size="30" /></td>
          </tr>
          <tr>
            <td>Contact Name:*</td>
            <td><input name="name" type="text" id="name" size="30" /></td>
          </tr>
          <tr>
            <td>Email:*</td>
            <td><input name="email" type="text" id="email" size="30" /></td>
          </tr>
          <tr>
            <td>Instructions:*</td>
            <td><textarea name="instructions" id="instructions" cols="30" rows="5"></textarea></td>
          </tr>
          <tr>
            <td>Quantity:</td>
            <td><input name="quantity" type="text" id="quantity" size="30" /></td>
          </tr>
          <tr>
            <td>Attach File #1:</td>
            <td><input name="file01" type="file" id="file01" size="30" /></td>
          </tr>
          <tr>
            <td>Attach File #2:</td>
            <td><input name="file02" type="file" id="file02" size="30" /></td>
          </tr>
          <tr>
            <td>Attach File #3:</td>
            <td><input name="file03" type="file" id="file03" size="30" /></td>
          </tr>
          <tr>
            <td> </td>
            <td><?php

require_once('recaptchalib.php');

// Get a key from http://recaptcha.net/api/getkey
$publickey = "****";
$privatekey = "****";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                header("Refresh: 0;url=quotesubmitted.php");
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?></td>
          </tr>
          <tr>
            <td> </td>
            <td><input name="loggedip" type="hidden" id="loggedip" value="<? echo getenv('REMOTE_ADDR'); ?>" /></td>
          </tr>
        </table>
        <div align="center">
          <input type="submit" name="submit" id="submit" value="Request Quote" />
        </div>
      </form>

Link to comment
https://forums.phpfreaks.com/topic/102710-captcha-issues/
Share on other sites

I managed to get it to work (had a space in the wrong place).  But if the captcha is wrong, it refreshes the page before it displays the error, and all the input data is lost.  Is there a way to make it echo w/o refreshing?  That way the page information isn't lost.

Link to comment
https://forums.phpfreaks.com/topic/102710-captcha-issues/#findComment-525956
Share on other sites

In your input values you would need to do something like:

 

<td><input name="name" type="text" id="name" size="30" value="<?php if(isset($_POST['name'])) echo $_POST['name'];?>" /></td>

 

As for the screen refreshing. When you're using a submit it will always refresh. To have the page not refresh you'd probably use javascript/ajax sort of thing.

 

I normally put my form processing code above the form and do the

 

<?php
if(isset($_POST['submit'])) {
   // form process stuff here
}
?>
<!--
  Form code here
-->

 

That way if the form is 'submitted' it will show the form still.

Link to comment
https://forums.phpfreaks.com/topic/102710-captcha-issues/#findComment-526007
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.