• Nim Barshad
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I work for a nonprofit, and I've been trying to adapt a web to lead form to use reCaptcha.  

I found a suggestion here: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008sR4IAI
In summary, you modify the salesforce web-to-lead form to submit to a verify.php file you create on your web server, and then that file uses "curl" ro resubmit the data to the original POST URL for the Salesforce web-to-lead

I've done my best to merge the reCaptcha directions (https://developers.google.com/recaptcha/docs/php) with the suggestions in the form (http://malebolgia.shadowsonawall.net/code-programming/captcha-with-salesforce.html) above, but when I go to submit my web to lead form, the verify.php file shows this error:
Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in D:\Hosting\4899791\html\about\verify.php on line 31

Line 31 of verify.php sets the value of a variable (for a custom Salesforce Lead field) to the one passed from the form- syntax looks like all the other fields being passed.  I'll post the full code at the end of my post

Another thing I've noticed is that the verify.php file that has the error is posting the value of these fields into the URL, so that seems to be OK.  Here's the URL
http://carolinatigerrescue.org/about/verify.php?oid=00DA0000000A32t
&retURL=http%3A%2F%2Fcarolinatigerrescue.org%2Fabout%2Fsubscribe-thanks.asp
&AccountType=Individual
&company=Self
&first_name=Barack
&last_name=Obama
&street=
&city=Washington
&state=DC
&zip=10018
&country=United+States
&email=AmandaByrne%40CarolinaTigerRescue.org
&emailOptOut=0
&00NA000000A0fWR=Subscribed+by+Request
&00NA000000A0fWH=Subscribed+by+Request
&recaptcha_challenge_field=(removed for security)
&recaptcha_response_field=asnomic+Hig
&submit=Subscribe

Can someone help me figure out where my syntax has gone wrong?

Verify.PHP code
<?php
  require_once('../includes/recaptchalib.php');
  $privatekey = "(removed for security)";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {

    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
// CTR curl code to resubmit to Salesforce web to lead
//set POST variables
  $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
  $fields = array(
     'oid'=>urlencode($oid),
     'recordType'=>urlencode($recordType),
     'retURL'=>urlencode($retURL),
     'first_name'=>urlencode($first_name),
     'last_name'=>urlencode($last_name),
     'company'=>urlencode($company),
     'street'=>urlencode($street),
     'city'=>urlencode($city),
     'state'=>urlencode($state),
     'zip'=>urlencode($zip),
     'country'=>urlencode($country),
     'email'=>urlencode($email),
     'emailOptOut'=>urlencode($emailOptOut),
     '00NA000000A0fWR'=>urlencode($00NA000000A0fWR),
     '00NA000000A0fWH'=>urlencode($00NA000000A0fWH),
    
   
    );

  //url-ify the data for the POST
  foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
  rtrim($fields_string,'&');

  //print_r($fields_string);

  //open connection
  $ch = curl_init();

  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_POST,count($fields));
  curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

  //execute post
  $result = curl_exec($ch);

  //close connection
  curl_close($ch);

  }
  ?>