Integrate Salesforce Lead with Contact Form 7 Plugin

Full thanks are going to Alex Hager. His tips is helped me lot and I successfully integrate salesforce lead with CF7 plugin.

First I generate a Web To Lead form in salesforce account. Here is my form’s code

<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <META> element to your page <HEAD>. -->
<!-- If necessary, please modify the charset parameter to specify the -->
<!-- character set of your HTML page. -->
<!-- ---------------------------------------------------------------------- -->

<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">

<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: Please add the following <FORM> element to your page. -->
<!-- ---------------------------------------------------------------------- -->

<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">

<input type=hidden name="oid" value="00XX000000XXXXX">
<input type=hidden name="retURL" value="http://yourdomain.com/thank-you/">

<!-- ---------------------------------------------------------------------- -->
<!-- NOTE: These fields are optional debugging elements. Please uncomment -->
<!-- these lines if you wish to test in debug mode. -->
<!-- <input type="hidden" name="debug" value=1> -->
<!-- <input type="hidden" name="debugEmail" value="[email protected]"> -->
<!-- ---------------------------------------------------------------------- -->

<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>

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

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

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

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

<label for="country">Country (text only)</label><input id="country" maxlength="40" name="country" size="20" type="text" /><br>

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

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

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

<label for="description">Description</label><textarea name="description"></textarea><br>

<input type="submit" name="submit">

</form>

Second I created my “Request More Info” form using Contact Form 7 plugin. Form is looking like this

Lastly I added the following code in functions.php file.

add_action( 'wpcf7_before_send_mail', 'gd_passing_data_web_to_lead' );
function gd_passing_data_web_to_lead(){
  $submission = WPCF7_Submission::get_instance();
  $data = $submission->get_posted_data();

  $first_name = $data['your-fname'];
  $last_name = $data['your-lname'];
  $company = $data['your-company'];
  $phone = $data['your-phone'];
  $email = $data['your-email'];
  $city = $data['your-city'];
  $country = $data['your-country'];
  $state = $data['your-state'];
  $message = $data['your-message'];
  $title = $data['your-subject'];

  $post_items[] = 'oid=00XX000000XXXXX'; // Replace this by your OID value
  $post_items[] = 'first_name=' . $first_name;
  $post_items[] = 'last_name=' . $last_name;
  $post_items[] = 'email=' . $email;
  $post_items[] = 'company=' . $company;
  $post_items[] = 'city=' . $city;
  $post_items[] = 'country=' . $country;
  $post_items[] = 'state=' . $state;
  $post_items[] = 'phone=' . $phone;
  $post_items[] = 'title=' . $title; 
  $post_items[] = 'description=' . $message; 
 
  if(!empty($first_name) && !empty($last_name) && !empty($email) && $data['_wpcf7'] == "792" )
  {
    $post_string = implode ('&', $post_items);
    // Create a new cURL resource
    $ch = curl_init();
 
    if (curl_error($ch) != "")
    {
      // error handling
      file_put_contents('cf7data.txt', 'Curl Error: ' . curl_error($ch));
    }
 
    $con_url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
    curl_setopt($ch, CURLOPT_URL, $con_url);
    // Set the method to POST
    curl_setopt($ch, CURLOPT_POST, 1);
    // Pass POST data
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string);
    curl_exec($ch); // Post to Salesforce
    curl_close($ch); // close cURL resource
  }

  //file_put_contents('cf7data.txt', $post_string); // Checking the data. is Data passing to hook?
}

I added this $data[‘_wpcf7’] == ‘792’ in the IF statement. 792 is “Request More Info” form ID. So Data of “Request More Info” form’s are going to my Salesforce lead only. When you will add my code, you’ll change this value by your form ID. That’s all.

Hope that this will help to other genesis peeps. Good Luck.

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.