I love this module - it is making our lives so much easier! The only problem I have with it is that the webform module no longer handles the submission of the form - so you don't get an email sent from the webform module, and the results for the forum submission are not being collected.

I've attached a patch (against the Drupal 5 version of the module) which makes a couple of small changes, instead of just changing the form action an additional submit handler has been added, this pings a POST request over to your Sugar using drupal_http_request - control is then handed back to the webform module and the form is handled as per any other normal webform.

Cheers,

Mike

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

metareason’s picture

+1 for this patch - just started writing the same kind of thing so that the webform validation isnt skipped then found this already written.

Seems to work so far, forms are validated, emailed and are also going neatly into Sugar.

Thanks!

pkrekelb’s picture

Wow, this is exactly what I need. I am actually trying to use sugarwebform to post webforms to another CRM (Eloqua), but I need this same functionality for forms such as for registration. I still need the fields to get posted to Drupal, but sent along to Eloqua as well.

Eloqua just has a few hidden fields I need to add.

Our site is Drupal 6. How different would this technique be in a sugarwebform-like module?

Thank you !
-Patrick

mdixoncm’s picture

The principle would be the same, just the syntax around the form handling would differ a little - if I get chance over the next week I'll roll a Drupal 6 version of the patch too (it's about time we moved our site onto 6 anyway!)

Cheers,

Mike

pkrekelb’s picture

That would be great. I may try to do the same, and if I do, I'll post it up.

webchuck’s picture

FileSize
8.64 KB

I actually found this patch a little too late, so I had already written up my own solution around the issue. I'll go ahead and post it here for anyone else. Mine is not quite as elegant as the above... I ended up rewriting the SugarWebform module entirely. But I like the simplicity of the solution because it no longer requires changes to Sugar's file system, a database table created or additional fields for the node form. You'll also notice that I removed the custom fields section, only because I never understood how they worked and didn't find them necessary.

The installation and usage instructions are found in INSTALL.txt. It uses PHP's cURL, so you'll need that on your server.

Hope this helps some other poor soul suffering with this integration.

drupalninja99’s picture

So should I use your module or the patch? Also I'm using the 6 version which is more updated so I'm really confused as to what is the path of least resistance. I could use your module and upgrade it manually integrate that patch, not sure what to do.

drupalninja99’s picture

FileSize
11.16 KB

Here is the d6 version of the patched module.

The only thing I haven't been able to figure out is how to upgrade the validation for the custom fields.

$form['#validate'] = array ('parse_custom_field_spec' => $form);
  
  return system_settings_form($form); 
}

function parse_custom_field_spec ($form_id, $form_values, $form) {
	$custom_fields = array();
	$custom_field_spec = $form_values['sugarwebform_custom_fields'];
	if ( !empty($custom_field_spec) ) {
		$custom_field_tmp = explode("\n", $custom_field_spec);
		foreach ( $custom_field_tmp as $field ) {
			if ( empty($field) ) break ;
			$new_field = explode("|", $field);
			$custom_fields[$new_field[0]] = $new_field[1];
		}
	}
	form_set_value($form['field_settings']['sugarwebform_custom_fields'], $custom_fields);
}

UPDATE: OK I tested this module and it didn't work so try my new module update below

drupalninja99’s picture

FileSize
13.16 KB

OK I've got an updated version of the d6 module that works pretty well I think. We are now using it on http://mediacurrent.com. I have integrated the patch drupal_http_request patch so that now the redirect works fine and also I added a feature for handling custom fields.

First of all I don't really understand the custom fields box on the settings page. It doesn't make sense to me at all.

What I ended up doing is making any component field key that isn't a standard CRM field be appended to the description. This is a little rough but I got it to work.

So my submit form function looks like this:

/**
 * Handle the submit of the webform - ping a POST request over to sugar
 */
function sugarwebform_submit_form(&$form, $form_state){

  $url = $form['#parameters'][2]->webform['sugarsettings']['sugarcrm_action'];
  $and_sign = false;

  /**
   * The following will take any webform field that is not a standard field in CRM and 
   * add that key/value to the description field in CRM so that data is not lost
   */
  include_once(drupal_get_path('module', 'sugarwebform') . "/sugarwebform_fields.inc"); 
  
  //go through each component and if it's not represented in CRM dump it all in the description field
  foreach ($form['#parameters'][2]->webform['components'] as $component) {
    $form_key = $component['form_key'];
    $field_name = $component['name'];
    
    if (!$sugarwebform_available_fields[$form_key]) {
      $form_state['values']['description'] .= $field_name . ': ';
      
      if (is_array($form_state['values'][$form_key])) {
        $form_state['values']['description'] .= "\n";
        
        foreach ($form_state['values'][$form_key] as $k => $v) {
          if ($v)
            $form_state['values']['description'] .= $v."\n"; 
        }
      }
      else
        $form_state['values']['description'] .= $form_state['values'][$form_key]."\n";
    }
  }
 
  $data = sugarwebform_flatten_form($form_state['values']);
  $data = ltrim($data,'&');
  
  if ($url){
    $result = drupal_http_request($url,array('Content-Type'=>'application/x-www-form-urlencoded',
                                            'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9')
                                  ,'POST',$data);
  }
  if ($result->code==200){
    $message = t('Valid response recieved from SugarCRM<br /><br />Data posted : !posted<br /><br />Content of response (an empty response is a good thing!): !response',
                  array('!posted'=>$data,'!response'=>$result->data));
    watchdog('SugarCRM',$message);  
  }
  else{
    $message = t('Failed to send request to !url response code was !code',array('url'=>$url,'code'=>$result->code));
    watchdog('SugarCRM',$message,WATCHDOG_ERROR);  
  }
}

It needs some work I'm sure but it works for me. It's a nice 1-size fits all solution for us bc now we can turn on CRM integration with very little configuration. For the standard field names I just have to make sure the component key (in advanced settings) matches the key I see in the sugarwebform_fields.inc file. After that any component with a different field key goes in the description. Works really well. Hope this helps!

This is a drupal 6 version.

drupalninja99’s picture

FileSize
13.05 KB

UPDATE: fixed big flaw, use this module instead.

drupalninja99’s picture

FileSize
12.97 KB

more fixes...

axon’s picture

Wow for someone new to Drupal.. and having istalled Drupal 6.x.. can anyone tell me how can I implement all those patches?

tks

axon’s picture

jaykali what Sugar URL are you using to post? index.php?entryPoint=WebToLeadCapture