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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Collecting profile information for multiple contacts with Drupal Forms API
Pages: [1] 2

Author Topic: Collecting profile information for multiple contacts with Drupal Forms API  (Read 2454 times)

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Collecting profile information for multiple contacts with Drupal Forms API
April 03, 2012, 03:23:40 pm
See this code:

Code: [Select]
function civicrm_advanced_fee_register_form_page_two($form_state) {

civicrm_initialize();

$edit = $form_state['values'];
global $user;
$category = 'Name and Address';

$form = civicrm_form_data($edit, $user, $category, true );

$category = 'New Individual';
$uid = 0;
$ctype = civicrm_get_ctype( 'Individual' );
    $html = CRM_Core_BAO_UFGroup::getEditHTML( null, $category, null, false, $reset, null, false, $ctype );

$form['additional-1'] = array(
'#title' => $category,
'#value' => $html,
// '#weight' => 1,
);

    $form['back'] = array(
        '#type' => 'submit',
        '#value' => '<< Back',
        // '#weight' => 10,
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Submit',
    );
   
//    drupal_set_message('<pre>' . print_r($form, TRUE) . '</pre>');

return $form;
}

Basically, this is part of a customized event registration driven by Drupal forms.  I am successfully updating the contact record of this form with the code added on line 9, and I am trying to collect information for an additional participant with the html generated on line 14 and put into the Drupal form on line 18.  The problem is, the values entered in the New Individual profile end up updating the logged in user's contact record when it should instead be creating a new contact or updating an existing record with a matching e-mail address.

What do I need to do differently to make the profile form generated on line 14 to create a new record or find/update the record by e-mail address?

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 04, 2012, 02:20:40 pm
Another piece of the puzzle:  When the logged-in user's contact information from civicrm_form_data(...) is submitted, it updates the contact's Home address, but it does not update the Email greeting, Postal greeting, or Addressee as it would if I directly edited their info from within civiCRM.  How, in this code, do I make that happen?

The CiviCRM-related part of my Drupal form submit function currently looks like this:

Code: [Select]
  // Create participant records for the logged-in user
civicrm_initialize();
global $user;
    require_once 'CRM/Core/BAO/UFMatch.php';
    // $result = civicrm_api("UFMatch","get", array ('version' =>'3','uf_id' => $user->uid));
$contact_id = CRM_Core_BAO_UFMatch::getContactId($user->uid);
$result = civicrm_api("Participant","create",array(
'version' => '3',
'contact_id' => $contact_id,
'event_id' => $form_state_values['event_id'],
'participant_fee_amount' => $fee_value,
'participant_source' => 'CiviCRM Advanced Fee',
'participant_status_id' => 5,
'role_id' => 1,
));
drupal_set_message('contact id is ' . $contact_id . print_r($result, TRUE));

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 13, 2012, 11:57:44 am
Bump - is this the right place to be asking this question?  Perhaps the CiviCRM blog or Confluence instead?  Thank you!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 13, 2012, 11:39:00 pm
Hmm - the problem is you are treading a path not many people are familiar with.

The most common approach to a customised event registration these days is to use the webform civicrm integration.

You'll be able to get a reasonable way using the

civicrm_api('contact','create',$params);

function - it should return the id of the newly created contact. I'm not too sure what other people are doing about checking whether the contact already exists - other than using civicrm_webform which has all that built in....
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 16, 2012, 01:02:36 pm
I'm now re-writing it to just pull a contact's information into standard Drupal form elements using the Civicrm API, and then to update the record through the API in the submit handler.  It does require an ahah callback and calls directly to CRM_Core_PseudoConstant::country() and CRM_Core_PseudoConstant::stateProvinceForCountry($country).  For the additional participants, I'll just create new contact records (it's impossible to know how to match them or if the main participant even has the right to register any existing contact) and let whoever else reconcile duplicates (there probably won't be that many).
« Last Edit: April 16, 2012, 01:04:47 pm by jakecivi »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 16, 2012, 01:25:05 pm
webform_civicrm will do that for you, and instead of spending your time writing FAPI and CiviAPI code, you can just focus on what matters. i.e. if you have extra logic you need done you can insert that code via a webform or civi hook.
I would strongly recommend that approach as it avoids reinventing the wheel.
See: http://vimeo.com/40119672
Try asking your question on the new CiviCRM help site.

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 17, 2012, 08:23:52 pm
The thing is I need things like a variable number of additional contacts depending on what someone selects in their event registration options.  I think that would preclude me from using a single webform node per event - I'd need to make multiple webforms to cover every possible number of participants, and that would be really messy.  I'm trying to make it easy for someone non-technical to create an event.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 17, 2012, 10:13:53 pm
Are you looking for something like this?
http://woolman.org/events/rsvp (please no test submissions)
This is a webform. No custom code. Fields are shown/hidden using the webform_conditional module. Also note the slick "same as my address" checkbox.
« Last Edit: April 17, 2012, 10:24:38 pm by colemanw »
Try asking your question on the new CiviCRM help site.

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 06:14:35 am
Does it also allow the admin to enter a complex fee structure based on length and lodging, calculate the fee automatically, and charge either a deposit or the full fee when someone signs up?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 08:41:48 am
Webform Integration does not handle event payments at all... but it gets you a lot farther down the road than you would be otherwise. I just did a job for a summer camp that had very similar needs to yours. The webform did most of the work (signing up multiple people for the event). Then I used a couple hooks to add the logic for payments and inject it into a specific contribution form.
Try asking your question on the new CiviCRM help site.

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 09:06:18 am
Did you use civicrm's payment system?  I'm needing to use Ubercart for its invoicing system, with some hooks into Ubercart's cart to allow for paying only a deposit upfront and then tracking how much is owed, and also to update the CiviCRM participant status once payment is received in full.  CiviCRM Accounting and Finance is unfortunately not ready yet, and I don't know if that will allow for deposit-only payments once it is.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 09:24:23 am
I created my own simple invoicing system that would look at the number of events they signed up for and total their price, and look at the total amount they had paid so far, and tally it up and display it to them. This allows payments to be made in any number of installments.
Try asking your question on the new CiviCRM help site.

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 09:26:13 am
What did you use to collect payments?  CiviCRM's contribution system?  Or did you write a miniature PayPal module for yourself or something along those lines?

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 09:39:17 am
I used a civi contribute form, and used my hook to add the invoice info to the top of the form.
Try asking your question on the new CiviCRM help site.

jakecivi

  • I post frequently
  • ***
  • Posts: 140
  • Karma: 0
Re: Collecting profile information for multiple contacts with Drupal Forms API
April 18, 2012, 09:45:53 am
I had no luck using a Drupal hook to add information to a Civi form.  I had to override the civicrm template.  Is there a way to do this from Drupal?  I suppose you could use drupal_add_js - but that doesn't degrade...

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Collecting profile information for multiple contacts with Drupal Forms API

This forum was archived on 2017-11-26.