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) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Adding custom fields to the Drupal register form - including CiviCRM
Pages: [1]

Author Topic: Adding custom fields to the Drupal register form - including CiviCRM  (Read 4036 times)

bhutten

  • Guest
Adding custom fields to the Drupal register form - including CiviCRM
March 18, 2010, 07:06:00 pm
Hi all:  I've been struggling with this problem for more than a week, so I guess it's time to ask the experts...  :)

My Drupal registration form has the Drupal "Username" and "Email address" fields on it, and the CiviCRM "First Name" and "Last Name" fields.  I did this by creating a custom "user-register.tpl.php" form, and it all works fine - when "Create an account" is clicked a Drupal user is created, a CiviCRM contact is created with the first name & last name from the form, etc.

However, I also want to put some checkboxes on that form, and when the user registers I want to check the values of those checkboxes and put the CiviCRM contact into some pre-defined groups.  I am trying to do this via the Drupal hook_user($op, &$form, &$account, $category = NULL). 

The problem is that when $op = 'insert', none of my custom fields (including, incidentally, the CiviCRM "first_name" and "last_name" fields) are in $form. The only fields in $form are the Drupal name and email fields.


What am I missing here? 

NOTE:  I've also tried using hook_form_alter to modify the registration form - in this case, I DO get my custom fields in $form in hook_user, BUT the CiriCRM contact record is created without the "first_name" and "last_name" fields from the registration form.  sigh.  I could really use some clarification/assistance.



Thanks

- bill

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Adding custom fields to the Drupal register form - including CiviCRM
March 19, 2010, 03:31:32 am
An alternative way you could do this without custom coding would be to use a CiviCRM profile attached to User registration and then make smart groups based around your checkboxes.

bhutten

  • Guest
Re: Adding custom fields to the Drupal register form - including CiviCRM
March 19, 2010, 06:49:34 am
Thanks for your reply. I was hoping to use a more custom approach because of the control it gives me, but I used your approach instead because it actually works.  I ended up adding the "Group(s)" field to my CiviCRM profile, and then marking the groups I wanted to use as "Public".  This all works very nicely - now I need to do some theme customization to make it look the way I need it to...

Thanks again.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Adding custom fields to the Drupal register form - including CiviCRM

This forum was archived on 2017-11-26.