Jump to content

PHP and ReCaptcha


Foosicle

Recommended Posts

 <table>
       <tbody bgcolor="#EFEFF5">
       <form name="helpform" method="post" action="">
        <div id="recaptcha">
	<?php require_once('include/recaptchalib.php');
  $publickey = "**************************** "; // you got this from the signup page
  echo recaptcha_get_html($publickey); 
  		?>
        </div>
          <tr id="contactform">
              <td>Your Email: </td>
              <td>
                	<input name="FROM" type="text" size="40" maxlength="30" value="<?php echo stripslashes(trim(htmlentities($FROM))) ?>" onFocus="this.value==this.defaultValue?this.value='':null">
              </td>
              </tr>
          <tr id="contactform">
              <td>First Name: </td>
              <td>
                	<input name="fname" type="text" size="40" maxlength="20" value="<?php echo stripslashes(trim(htmlentities($fname)))?>" onFocus="this.value==this.defaultValue?this.value='':null">
              </td>
          </tr>
          <tr id="contactform">
              <td>Last Name: </td>
              <td>
                	<input name="lname" type="text" size="40" maxlength="20" value="<?php echo stripslashes(trim(htmlentities($lname)))?>" onFocus="this.value==this.defaultValue?this.value='':null">
              </td>
          </tr>
          <tr id="contactform">
              <td>Message: </td>
              <td>
            	<textarea name="message" rows="5" cols="31" maxlength="200" value="<?php echo stripslashes(trim(htmlentities($message)))?>" wrap="physical"></textarea>
              </td>
          </tr>
              </tr>
          <tr>
          		<td>
                <input type="submit" value="Submit" action="mail()">
                </td>
          </tr>
          
          </form>

Link to comment
Share on other sites

here comes the error ;)

 

my verify file looks like:

<?php
	 $errors = array();

 //READ the user recaptcha
 require_once('recaptchalib.php');
 $privatekey = "******************************";
 $resp = recaptcha_check_answer ($privatekey,
								 $_SERVER["REMOTE_ADDR"],
								 $_POST["recaptcha_challenge_field"],
								 $_POST["recaptcha_response_field"]);

 //READ the posted form data
 $fromemail = $_POST['fromemail'];
 $fname = $_POST['fname'];
 $lname = $_POST['lname'];
 $message = $_POST['message'];

 //VALIDATE form data exists
     if(!isset($frommail) ||
        !isset($fname) ||
        !isset($lname) ||
        !isset($message)){
	echo 'We are sorry, but there appears to be a problem with the form you submitted.';      
     }else{
	echo 'success';
	}

	$fromemail = stripslashes($fromemail);
	$fname = stripslashes($fname);
	$lname= stripslashes($lname);
	$message = stripslashes($message);

	$fromemail = trim(htmlentities($fromemail));
	$fname = trim(htmlentities($fname));
	$lname= trim(htmlentities($lname));
	$message = trim(htmlentities($message));

	//VALIDATE !errors
  if (!empty($errors)){
	redirect_to("http://www.*******.com/index.php");	
	}

	//CREATE the email form data
	$to = "customerservice@*******.com"; 
	$subject = $fname . " " . $lname;
	$headers = "From: " . $fromemail;


  if (!$resp) {
	   // What happens when the CAPTCHA was entered incorrectly
	   echo ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
			"(reCAPTCHA said: " . $resp->error . ")");
  }else {
   // Your code here to handle a successful verification
   echo "SUCCESS!";
  }


	mail($to, $subject, $message, $headers);

?>

Link to comment
Share on other sites

//VALIDATE form data exists

   

 if(!isset($frommail) ||
        !isset($fname) ||
        !isset($lname) ||
        !isset($message)){
	echo 'We are sorry, but there appears to be a problem with the form you submitted.';      
     }else{
	echo 'success';
	}

 

This gives me err.

'We are sorry, but there appears to be a problem with the form you submitted.'

Link to comment
Share on other sites

In an effort to validate safe data I have attempted to implement stripslashes, trim, and htmlentities...

How does that code look?

               

                $fromemail = stripslashes($fromemail);

$fname = stripslashes($fname);

$lname= stripslashes($lname);

$message = stripslashes($message);

 

$fromemail = trim(htmlentities($fromemail));

$fname = trim(htmlentities($fname));

$lname= trim(htmlentities($lname));

$message = trim(htmlentities($message));

Link to comment
Share on other sites

$recaptcha_challenge_field = $_POST["recaptcha_challenge_field"];

$recaptcha_response_field = $_POST["recaptcha_response_field"];

 

echo $recaptcha_challenge_field;

echo $recaptcha_response_field;

 

so according to this.. they are not getting posted.

strange because I have no way of seeing the code in the form other than :

           

            <?php

            require_once('include/recaptchalib.php');

              $publickey = "************************-******* ";

            // you got this from the signup page

              echo recaptcha_get_html($publickey);

              ?>

 

So if that is not displaying anything.. should i worry? and how?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.