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) »
  • Membership custom data in a sign-up form
Pages: [1]

Author Topic: Membership custom data in a sign-up form  (Read 1255 times)

chiebert

  • I post occasionally
  • **
  • Posts: 50
  • Karma: 1
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Membership custom data in a sign-up form
March 18, 2012, 08:12:59 am
I've got a custom data group assigned to a 'membership' type, with two fields in which I want to record the Drupal webform nid and sid (more on that in a sec). I've created a profile that has these fields, and I've added that profile to a Membership Contribution Page. I've successfully grabbed the nid and sid from the url in a BuildForm hook, and (also successfully) $form->setDefaults() for the two custom fields - they show up as expected on my membership contrib form.

However: when I submit the form, the membership is created, but the custom data is not saved.

Any thoughts? Holes in my process? Suggestions or incantations? ;)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Membership custom data in a sign-up form
March 18, 2012, 08:17:07 am

you also need to implement the postProcess hook and save the values to the DB in that hook

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

chiebert

  • I post occasionally
  • **
  • Posts: 50
  • Karma: 1
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Membership custom data in a sign-up form
March 18, 2012, 08:22:27 am
I wondered as much, but where is the relevant membershipId to be found once I'm I'm postProcess? I understand that the membership itself (as well as the contribution?) has been created at that point, and I'm itching to chain some API calls in response, but don't know how to get those key ids...

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Membership custom data in a sign-up form
March 18, 2012, 01:37:57 pm

Just do a debug print on the form and see what variables are available that you can reuse

some of the hooks came in a lot later and many of those variables which hold various IDs are not class variables. We fix them on a as needed basis :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

chiebert

  • I post occasionally
  • **
  • Posts: 50
  • Karma: 1
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Membership custom data in a sign-up form
March 19, 2012, 09:10:49 am
Okay, using API v3, would I then do something like the following (meaning, this is what I tried, without luck)?

Code: [Select]
    $params = array(
      'membership_id' => $form->_values['membership_id'],
      'custom_15' => $form->_submitValues['custom_15'],
      'custom_16' => $form->_submitValues['custom_16'],
      'version' => 3,
    );
   
    require_once 'api/api.php';
    $result = civicrm_api( 'membership','update',$params );

I've confirmed that those _submitValues are there in the $form object at the time the above api is called, and the $result array returns is_error = 0 and all the other expected values from the membership creation. But the custom data values haven't been set for the membership in question.

chiebert

  • I post occasionally
  • **
  • Posts: 50
  • Karma: 1
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Membership custom data in a sign-up form
March 19, 2012, 10:33:52 am
Okay - turns out I had set the custom data fields to 'view only' in the UI. That's why they weren't being update via profile. Don't know if that's also why the api call didn't work, but I'll check on that later. For now the original problem is solved.

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Membership custom data in a sign-up form
March 22, 2012, 07:58:44 pm
For some reason the API won't update fields that are set to "backend only" which makes me wonder how we are supposed to be setting them from the backend if not with the API.
Try asking your question on the new CiviCRM help site.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Membership custom data in a sign-up form

This forum was archived on 2017-11-26.