WordPress Sage CRM Web 2 Lead

If you run a WordPress website and Contact Form 7 plugin is your form manager and specifically you have a Contact Us form, then you can use WordPress Hooks to automatically create a leads in Sage CRM whenever the form is submited

  1. Locate your theme functions.php file which should be found in public_html/wp-content/themes/ACTIVE_THEME_NAME/

Add the following code to the end of the file

function action_create_sagecrm_lead( $contact_form ) { 
   
    $submission = WPCF7_Submission::get_instance();  
    if ( $submission ) {
        $posted_data = $submission->get_posted_data();

        $url = 'http://CRM_SERVER/CRM_INSTALL/eware.dll/SubmitLead?RuleID=';
        $data = array(
            'lead_description' => $posted_data['subject'],
            'lead_details' => $posted_data['message'],
            'lead_companyname' => $posted_data['company-name'],
            'lead_personlastname' => $posted_data['lastname'],
            'lead_personfirstname' => $posted_data['firstname'],
            'lead_personemail' => $posted_data['email'],
            );
                        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec($ch);
        curl_close ($ch);

    }

}; 
add_action( 'wpcf7_mail_sent', 'action_create_sagecrm_lead', 10, 1 );

This will register a hook for the email sent event which is called after the Contact Form 7 has is done with sending the email. Further, the hook action will be executed and using PHP cURL method will post the form data to your Sage CRM web 2 lead action.

You will have to modify the $url variable to match your crm server and crm install name

$url = 'http://CRM_SERVER/CRM_INSTALL/eware.dll/SubmitLead?RuleID=';

And secondly modify the $data array to match your Contact Form 7 field names and map them to the desired Sage CRM Lead fields

$data = array(
            'lead_description' => $posted_data['subject'],
            'lead_details' => $posted_data['message'],
            'lead_companyname' => $posted_data['company-name'],
            'lead_personlastname' => $posted_data['lastname'],
            'lead_personfirstname' => $posted_data['firstname'],
            'lead_personemail' => $posted_data['email'],
            );

The code can be adapted to work with any other WordPress Forms plugins

This approach is an alternative to replacing your wordpress contact form with the HTML form generated by the Sage CRM Web2Lead

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>