Skip to main content

How to capture SugarCRM leads in Drupal

An article from ComputerMinds - Building with Drupal in the UK since 2005.
31st Dec 2008

Mike Dixon

Senior Mind

We are big fans of SugarCRM and have worked on a number of projects to integrate SugarCRM with Drupal. This is a simple guide to performing a basic data capture integration between Drupal and Sugar, using a couple of Drupal modules (webform and sugarwebform). You can see an example of this on our contact us page - feel free to fill the form in, but it is our live contact form so don't be suprised if you get a callback :)

Install the Drupal Sugar modules

We are assuming here that you have both SugarCRM and Drupal up and running. The next step is to download and install the webform ( ) and the sugarwebform ( ) modules - they are both available for Drupal 5 and Drupal 6, so make sure you pick the correct version.

Configure your SugarCRM installation

This bit is fun. You need to "override" the leadCapture.php file that is in the root directory of your Sugar installation. Confusingly (and luckily) you don't actually edit this file itself, but instead create a new file called leadCapture_override.php. Copy the contents of the default-leadCapture_override.php file that comes free with sugarwebform module into this new file, you will need to change the users bit at the top. This is a little confusing - the code looks like this.

$users = array(
    'name1' => array('name'=>'username', 'pass'=>'user_hash')
  • name1 - this can be anything you like, BUT remember it as you will need it later when configuring your webform. Personally I just use the username here
  • username - this is a name of a valid user in your SugarCRM database, you might want to create a user just for web submissions
  • user_hash - you need to get this from the Sugar database, it's in the users table

Build a Drupal webform

If you've not used the webform module before you might want to have a look at the webform section of the handbook which will run you through the process of building a simple webform. If you're awake you might have noticed that the sugarwebform module has added a couple of fields to the top of the webform node submission page (see image below).

Apologies, but we lost the images in a server migration.

  • Sugar form - the URL of your leadcapture page, i.e. (keep the leadCapture.php bit on the end)
  • Lead Source - this will appear in the "lead source" section of the lead (suprise suprise!), BUT you need to make sure the value here matches a value in the lead source "dropdown". You can edit these in the admin -> dropdown section within Sugar.
  • SugarCRM User - this name here needs to match 'name1' (see above)

Nearly there, just need to tie the Drupal webform to the Sugar lead form

So we now have a webform, hopefully with some sensible fields (name, email etc). We now need to set the "field key" on each of these fields to tie the Drupal webform field into a SugarCRM field. You can see an example below of a first name field

Apologies, but we lost the images in a server migration.

Here are the available field keys that you can use in your webforms

  • description
  • lead_source_description
  • status_description
  • refered_by
  • salutation
  • first_name
  • last_name
  • account_name
  • title
  • department
  • phone_work
  • phone_mobile
  • phone_home
  • account_name
  • phone_other
  • phone_fax
  • email1
  • email2
  • do_not_call
  • email_opt_out
  • primary_address_street
  • primary_address_city
  • primary_address_state
  • primary_address_postalcode
  • primary_address_country
  • alt_address_country
  • alt_address_street
  • alt_address_city
  • alt_address_state
  • alt_address_postalcode

UPDATE - you might want to check out this patch for the sugarwebform module - - which allows the webform module to handle the submission of your webform, which means emails get sent and results get recorded

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.