2

I have a webform where our users can add new contacts to CiviCRM. This form creates an activity record. And this form should create a membership for these contacts. The membership has some custom fields; let's say field Reason and has values "Good, Bad, Audit" and a Referral field that contains the name of a person.

So far, this is standard CiviCRM Webform. I can create the new contact record, create their membership, and populate the membership custom field with the option that the user selects.

Now, this webform allows users to select existing contacts. Those existing contacts already have a membership, and already have a value in that Reason field.

My goal is that for existing contacts, IF the user selects "Audit" for the reason field, then the membership does not update. So the membership record, membership type, membership dates, Referral custom field and Reason custom field should stay the same as what they were previously. But this only happens if the Reason custom field is selected as "Audit". For any other reason field value, the membership should update as normal.

What I have tried:

  • I can't figure out how to do this using webform conditionals. Is there a way? I would need to somehow capture the contact's membership field values before the user submits the contact.
  • Could I do this with a webform hook? In that case, which hook should I be looking at so that it processes before the webform/civicrm integration?
  • I looked at using CiviRules, with the Webform CiviRules integration, but this seems to fire after the webform is submitted.

Thank you

2 Answers 2

1

I think you could use hook_webform_submission_presave

http://api.drupal.psu.edu/api/drupal/modules%21contrib%21webform%21webform.api.php/group/webform_hooks/nittany7

But hook_civicrm_pre might be better https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/

4
  • Please note this hook is too late for anything webform_civicrm Jul 31, 2019 at 13:16
  • by "this hook" you mean hook_webform_submission_presave ? or hook_civicrm,_pre ? or both?
    – ericG
    Aug 27, 2019 at 16:33
  • submission_presave Aug 27, 2019 at 17:41
  • thanks for pointing that out
    – ericG
    Aug 29, 2019 at 18:43
1

You’ll need to intercept on validate -> so a hook_form_alter with a custom validate. Here is an example.

https://drupal.stackexchange.com/questions/22952/custom-validation-for-a-form

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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