3

I want to run a database query in another CRM database after a user has registered. I have the following function in my sugar_crm module eg:

function sugar_crm_user_register_submit($form, &$form_state)
{       
    // some code to run a database query in SugarCRM
    ddl("User registration form submitted to CRM");         

}

However, the function doesn't appear ever to be called. What am I doing wrong here?

  • what is your drupal version 6 or 7? – Yusef Sep 5 '12 at 16:00
  • My current version is Drupal 7 – Dylan Spencer James Sep 5 '12 at 16:02
5

A way is add a submit function to user_register_form submits in form alter.

yourmodule_form_alter(&$from,$form_state,$form_id) {
  if ($form_id == 'user_register_form ) { 
       $form['#submit'][] = 'sugar_crm_user_register_submit';
       }
 }

but I think the better way is setup your custom function in hook_user_insert.this hook triggered when a user registered . you can implement it in your custom module.

  function yourmodule_user_insert(&$edit, $account, $category) {
   // some code to run a database query in SugarCRM
  ddl("User registration form submitted to CRM"); 
  }
  • hook_user_insert was exactly what I was looking for. Thanks. I guess I just need to become more familiar with the API! – Dylan Spencer James Sep 5 '12 at 16:25
  • Yes. working with drupal needs familiarity with drupal api. I pleasured could help you. :) – Yusef Sep 5 '12 at 16:30
2
function sugar_crm_user_insert(&$edit, $account, $category) {

  // some code to run a database query in SugarCRM

    ddl("User registration form submitted to CRM");  
}

This code worked for me in D7.

For D6,

function scrm_user($op, &$edit, &$account, $category = NULL) {

  if ($op == 'insert' || $op == 'update' )  {

  // some code to run a database query in SugarCRM

    ddl("User registration form submitted to CRM"); 
  }
}
1

Do you have the '#submit' property inside your hook_form_alter() ? E.g

 <?php 
    function sugar_crm_form_alter(){
// Call the  submit handler    
$form['#submit'][] = 'sugar_crm_user_register_submit';
    }
    ?>
  • I didn't. I've added that in now, and the _user_register_submit function still doesn't get called. – Dylan Spencer James Sep 5 '12 at 15:53
  • Right, I think I've worked it out. I needed to define the $form in the function signature. EG sugar_crm_form_alter(&$form) – Dylan Spencer James Sep 5 '12 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.