CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 3.4 and 4.0 Releases Testing »
  • Creating Drupal Users Via Profile on Contribution Pages (Beta 3)
Pages: [1]

Author Topic: Creating Drupal Users Via Profile on Contribution Pages (Beta 3)  (Read 2436 times)

lkacenja

  • I’m new here
  • *
  • Posts: 18
  • Karma: 2
Creating Drupal Users Via Profile on Contribution Pages (Beta 3)
April 08, 2011, 03:04:32 pm
I'm trying to create a Drupal user account via a contribution form with suitable profile included. The result is the following warnings and no Drupal account being created:

Code: [Select]
• Warning: array_merge() [function.array-merge]: Argument #2 is not an array in drupal_retrieve_form() (line 755 of /includes/form.inc).
• Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'user_register' was given in drupal_retrieve_form() (line 771 of /includes/form.inc).

I think I've traced the issue to createDrupalUser on line 485 of CMSUser.php. The only headway I've been able to make is that the user form id has changed in Drupal 7 to user_register_form. Altering all of the form function calls to use this ID gets rid of the warnings, but still doesn't create an account. I am not very familiar with creating users in this manner in Drupal 6, so my knowledge of doing it in Drupal 7 is minuscule. I've included the function below for reference, and the changes I've made so far beneath that. Thanks.

Code: [Select]
    static function createDrupalUser( &$params, $mail )
    {
        $form_state['values']  = array (
                                    'name' => $params['cms_name'],
                                    'mail' => $params[$mail],
                                    'op'   => 'Create new account'
                                    );
        if ( !variable_get('user_email_verification', TRUE )) {
            $form_state['values']['pass']['pass1'] = $params['cms_pass'];
            $form_state['values']['pass']['pass2'] = $params['cms_pass'];
        }

        $config = CRM_Core_Config::singleton( );

        // we also need to redirect b
        $config->inCiviCRM = true;

        $form = drupal_retrieve_form('user_register', $form_state);
        $form['#post'] = $form_state['values'];
        drupal_prepare_form('user_register', $form, $form_state);

        // remove the captcha element from the form prior to processing
        unset($form['captcha']);
       
        drupal_process_form('user_register', $form, $form_state);
       
        $config->inCiviCRM = false;
       
        if ( form_get_errors( ) ) {
            return false;
        }

        // looks like we created a drupal user, lets make another db call to get the user id!
        $db_cms = DB::connect($config->userFrameworkDSN);
        if ( DB::isError( $db_cms ) ) {
            die( "Cannot connect to UF db via $dsn, " . $db_cms->getMessage( ) );
        }

        //Fetch id of newly added user
        $id_sql   = "SELECT uid FROM {$config->userFrameworkUsersTableName} where name = '{$params['cms_name']}'";
        $id_query = $db_cms->query( $id_sql );
        $id_row   = $id_query->fetchRow( DB_FETCHMODE_ASSOC ) ;
        return $id_row['uid'];
    }

With my changes:
Code: [Select]
static function createDrupalUser( &$params, $mail )
    {
        $form_state['values']  = array (
                                    'name' => $params['cms_name'],
                                    'mail' => $params[$mail],
                                    'op'   => 'Create new account'
                                    );
        if ( !variable_get('user_email_verification', TRUE )) {
            $form_state['values']['pass']['pass1'] = $params['cms_pass'];
            $form_state['values']['pass']['pass2'] = $params['cms_pass'];
        }
       
        $form_state['build_info']['args'] = array();

        $config = CRM_Core_Config::singleton( );

        // we also need to redirect b
        $config->inCiviCRM = true;

        $form = drupal_retrieve_form('user_register_form', $form_state);
       
        $form['#post'] = $form_state['values'];
        drupal_prepare_form('user_register_form', $form, $form_state);

        // remove the captcha element from the form prior to processing
        unset($form['captcha']);
       
        $form_state['method'] = 'post';
        $form_state['process_input'] = 1;
        $form_state['submitted'] = 1;
       
        drupal_process_form('user_register_form', $form, $form_state);
       
        $config->inCiviCRM = false;
       
        if ( form_get_errors( ) ) {
            return false;
        }

        // looks like we created a drupal user, lets make another db call to get the user id!
        $db_cms = DB::connect($config->userFrameworkDSN);
        if ( DB::isError( $db_cms ) ) {
            die( "Cannot connect to UF db via $dsn, " . $db_cms->getMessage( ) );
        }

        //Fetch id of newly added user
        $id_sql   = "SELECT uid FROM {$config->userFrameworkUsersTableName} where name = '{$params['cms_name']}'";
        $id_query = $db_cms->query( $id_sql );
        $id_row   = $id_query->fetchRow( DB_FETCHMODE_ASSOC ) ;
        return $id_row['uid'];
    }

Leo Kacenjar
Web Developer
Open Media Foundation

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Creating Drupal Users Via Profile on Contribution Pages (Beta 3)
April 09, 2011, 08:27:33 am
Hi, Looks like a bug for CiviCRM 4.0.x.
Created an issue here http://issues.civicrm.org/jira/browse/CRM-7891.
Thanks for the patch, I will check this and will commit in coming CiviCRM 4.0.x.

Thanks,
Rajan

lkacenja

  • I’m new here
  • *
  • Posts: 18
  • Karma: 2
Re: Creating Drupal Users Via Profile on Contribution Pages (Beta 3)
April 12, 2011, 08:29:09 am
Thanks Rajan,

We updated that file with the latest source and it seems to have resolved that bug. I appreciate the help.

-Leo
Leo Kacenjar
Web Developer
Open Media Foundation

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Alpha and Beta Release Testing »
  • 3.4 and 4.0 Releases Testing »
  • Creating Drupal Users Via Profile on Contribution Pages (Beta 3)

This forum was archived on 2017-11-26.