Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: PHP  |  size: 1.27 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require_once("recaptchalib.php");
  2. $privatekey = "--your private key--";
  3. if (isset($_POST['submit'])) {
  4.         $resp = recaptcha_check_answer ($privatekey,
  5.         $_SERVER["REMOTE_ADDR"],
  6.         $_POST["recaptcha_challenge_field"],
  7.         $_POST["recaptcha_response_field"]);
  8.        
  9.         if (!$resp->is_valid) {
  10.                 // What happens when the CAPTCHA was entered incorrectly
  11.                 $error = "The reCAPTCHA wasn't entered correctly. Please try it again." . "(reCAPTCHA said: " . $resp->error . ")";
  12.         } else {
  13.                 // Valid captcha entry, proceed to submit to salesforce
  14.  
  15.                 /* This code passes all get and post variables to salesforce for logging, since captcha has been verified */
  16.                 $ch = curl_init('https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8');
  17.                 $encoded = '';
  18.                 // include GET as well as POST variables; your needs may vary.
  19.                 foreach($_GET as $name => $value) {
  20.                   $encoded .= urlencode($name).'='.urlencode($value).'&';
  21.                 }
  22.                 foreach($_POST as $name => $value) {
  23.                   $encoded .= urlencode($name).'='.urlencode($value).'&';
  24.                 }
  25.                 // chop off last ampersand
  26.                 $encoded = substr($encoded, 0, strlen($encoded)-1);
  27.                 curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
  28.                 curl_setopt($ch, CURLOPT_HEADER, 0);
  29.                 curl_setopt($ch, CURLOPT_POST, 1);
  30.                 curl_exec($ch);
  31.                 curl_close($ch);
  32.        
  33.         }
  34. }