Good Morning Ladies and Gents,

I am having the following issue. I have implemented a captcha widget to my downloads page since there were a log of spam files that were coming through. After hours of working on this I have finally gotten the Captcha app to work and forward after successful entry to the actual download page.

However, the lead info that was inputted in the form is not being forwarded as a lead at all. My guess is that the code is missing in the verify.php file. But I am not entirely too sure. Might have taken on a bit too much of a project with this one.

FORM.PHP

<form action="verify.php" method="POST">
<input type=hidden name="oid" value="SALESFORCE I.D.">
<input type=hidden name="retURL" value="/downloads.php">
  <label for="first_name"><br />
    <strong>(*) Fields that are required </strong><br />
    <br />
    First Name (*)</label><br />
  <input  id="first_name" maxlength="40" name="first_name" size="20" type="text" required="required" /><br>

  <label for="last_name">Last Name (*)</label> <br />
  <input  id="last_name" maxlength="80" name="last_name" size="20" type="text" required="required"  /><br>

  <label for="email">Email (*)<br />
  </label>
  <input  id="email" maxlength="80" name="email" size="20" type="text" required="required" /><br>

  <label for="phone">Phone <br />
  </label>
  <input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

  <label for="company">Company <br />
  </label>
  <input  id="company" maxlength="40" name="company" size="20" type="text" /><br>

  <label for="city">City <br />
  </label>
  <input  id="city" maxlength="40" name="city" size="20" type="text" /><br>

  <label for="state">State/Province <br />
  </label>
  <input  id="state" maxlength="20" name="state" size="20" type="text" /><br>

  <label for="country">Country <br />
  </label>
  <input  id="country" maxlength="40" name="country" size="20" type="text" /><br><br>
  <strong>Interest (hold Ctrl (Windows) / Command (MacOsX) to select more than one)</strong></p>
<select  id="SALESFORCE_ID" multiple="multiple" name="SALESFOCE_NAME" title="Interest"><br>
<option value="C5">C5</option>
<option value="D5">D5</option>
<option value="Dispensing">Dispensing</option>
<option value="In-Line">In-Line</option>
<option value="M7">M7</option>
<option value="M75">M75</option>
<option value="M7 HP">M7 HP</option>
<option value="M8 Cube">M8 Cube</option>
<option value="M8">M8</option>
<option value="M85">M85</option>
<option value="M10 Pro">M10 Pro</option>
<option value="M10 Power">M10 Power</option>
<option value="ML">ML</option>
<option value="MXL">MXL</option>
</select>
<br>
<label for="lead_source"></label>
<input id="lead_source" maxlength="40" name="lead_source" size="20" option value="Web Form" type=hidden />
<?php
require_once('recaptchalib.php');
    $publickey = "PUBLIC_GOOGLE_cAPTCHA_kEY";
    echo recaptcha_get_html($publickey);
?>
<input type="submit"/>
</form><p> </p>

VERIFY.PHP

<?php
 require_once('recaptchalib.php');
 $privatekey = "GOOGLE CAPTCHA PRIVATE KEY";
 $resp = recaptcha_check_answer ($privatekey,
                                 $_SERVER["REMOTE_ADDR"],
                                 $_POST["recaptcha_challenge_field"],
                                 $_POST["recaptcha_response_field"]);
 if (!$resp->is_valid) {
   // What happens when the CAPTCHA was entered incorrectly
   die ("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 '<META HTTP-EQUIV="Refresh" Content="0; URL=downloads.php">';
//    header("Location: https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8");
//    $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
exit;
 }
 ?>

In the above coding the last two lines:

//header("Location: https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8");
// $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

Are my guess as to where I should be pointing the forward. However, I thoroughly believe that I am missing something else as I feel as though the SF ID and user name are missing.

Certain values have been replaced due to security reasons. Please let me know if you could further assist with the following to make sure that I can get this thing going as every other hour or so I am getting some spam message from China,

Thank you.

Emanuel.

You cannot redirect the user to one page, whilst still submitting the form details to Sales Force in the manner you're trying.

I did something similar a few months back and chose to use cURL to post the form values directly to Sales Force.

I've taken the code from an Enquiry class I wrote and packaged it up in a function.

/**
 * Capture web lead in Sales Force CRM.
 *
 * @param array $data
 * @return boolean
 */
function capture_lead(array $data)
{
    // Prepare request URL
    $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

    // Prepare lead
    $lead = array(
        'oid'         => 'XXXXXX',
        //'debug'       => 1,
        //'debugEmail'  => $data['recipient'],
        'first_name'  => $data['first_name'],
        'last_name'   => $data['last_name'],
        'title'       => $data['job_title'],
        'company'     => $data['company'],
        'email'       => $data['email'],
        'phone'       => $data['phone'],
        'country'     => $data['country'],
        'description' => $data['description'],
        'lead_source' => 'Web',
        'retURL'      => '',
    );

    // Initialise new cURL session and set cURL options
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL            => $url,
        CURLOPT_HEADER         => false,
        CURLOPT_POST           => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 5,
        CURLOPT_POSTFIELDS     => http_build_query($lead),
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => true,
        CURLOPT_FOLLOWLOCATION => true,
    ));

    // Store cURL session response
    $response = (bool) curl_exec($curl);

    // Check that no error was returned
    if(false <> curl_error($curl))
        $response = false;

    // Close cURL session
    curl_close($curl);
    return $response;
}

Hope this helps.

Would this be an insert in the form.php file or the verify.php file?

I might be asking a lot here but if possible I would have to ask for the coding in the correct spot for just a copy and paste. This truely isnt my fortay :/

Initially the inquiry was just an implementation of Saleforce which I completed. Then the REQ for Salesforce Web2Lead came in and thats when I got flustered with this entire scenario.

Other thought I had was possible running another php from the verify to input the info into Salesforce. But my guess is that wouldnt work out either correct?

Would this cURL have a captcha involved to handle the spam issue or is that not the case here?

You would add the function to verify.php and call the function, capture_lead($_POST) on line 14 before you redirect to download.php.

You would then need to update the lead array within the function so that the array keys and corresponding data indexes match the SalesForce fields you wish to populate and your form field names sync up accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.