Brandon M. West

6Feb/101

Posting a Lead to SugarCRM from Drupal via Webform

I was helping a friend solve the issue of capturing a lead to Sugar 5.2 from a form in Drupal 6 and my searching was not turning up a clear answer. This article was a good start but was a bit out of date and missing a couple steps. On the issues page for the SugarCRM Drupal module, I found a couple other useful hints. This guide should work for Drupal 6 and SugarCRM 5.1+.

First, download these Drupal modules: SugarCRM Webform Integration and Webform. Extract these archives to your server and activate the modules in Drupal.

Create a new file named leadCapture_override.php in the root folder of your SugarCRM install on your server. Open the file and paste the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# set up the array of usernames and hashed password
$users = array(
'Your_User_Name' => array('name'=>'Your_User_Name', 'pass'=>'Your_User_Hash','userid'=>'Your_User_Id')
);

# identify the web site user by id so we can assign the lead to them
$assigned_user_id = $users[$_REQUEST['user']]['userid'];

if( !isset($_POST['assigned_user_id']) || !empty($_POST['assigned_user_id']) ){
$_POST['assigned_user_id'] = $assigned_user_id;
}

# if we have an Opt-In field, we want to get rid of any Opt-Out field that we may have
if ( !empty($_POST['email_opt_in']) ) {
unset($_POST['email_opt_out']);
}

# convert opt out to an explicit binary boolean
if ( isset($_POST['email_opt_out']) ) {
$_POST['email_opt_out'] = 1;
}

Now you will need to enter your configuration's user values In the $users array declaration (line 3 above). First enter the SugarCRM user name that will be assigned every lead coming from Drupal. Once you have the user name, replace Your_User_Name in the code above with it.

To get the userid and pass values, open your SugarCRM database with a database admin (such as phpMyAdmin) and run the following query: SELECT id, user_hash FROM users WHERE user_name='Your_User_Name'. Replace Your_User_Id with the id value, and Your_User_Hash with the user_hash value.

The next step is creating your webform. For the purposes of this article I am assuming that all the fields you need to capture are already setup in Sugar. If not, maybe this screencast can help. If you need any help creating the webform, more information can be found in the Drupal documentation.

Once you have your webform created, you will see a SugarCRM Settings area on the webform configuration screen.

In the Sugar Form is posted to field, enter http://yoursugarinstanceURL/index.php?entryPoint=leadCapture. Lead Source can be whatever you'd like. The SugarCRM User field must match the value you entered for Your_User_Name in the leadCapture_override.php file created earlier.

Congratulations, your Drupal form should now capture leads in Sugar.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Comments (1) Trackbacks (0)
  1. This should come in handy! ;)


Leave a comment


No trackbacks yet.

Page optimized by WP Minify WordPress Plugin