Answers.Body: <p>You’ll need to intercept on validate -> so a hook_form_alter with a custom validate. Here is an example.</p>
  
  <p><a href="https://drupal.stackexchange.com/questions/22952/custom-validation-for-a-form">https://drupal.stackexchange.com/questions/22952/custom-validation-for-a-form</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-30T05:44:37.323Z
Answers.LastActivityDate: 2019-06-30T05:44:37.323Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>I think you could use hook_webform_submission_presave </p>
  
  <p><a href="http://api.drupal.psu.edu/api/drupal/modules%21contrib%21webform%21webform.api.php/group/webform_hooks/nittany7" rel="nofollow noreferrer">http://api.drupal.psu.edu/api/drupal/modules%21contrib%21webform%21webform.api.php/group/webform_hooks/nittany7</a></p>
  
  <p>But hook_civicrm_pre might be better
  <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_pre/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T13:16:42.987Z
Answers.Text: Please note this hook is too late for anything webform_civicrm
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-27T16:33:41.343Z
Answers.Text: by "this hook" you mean hook_webform_submission_presave ? or hook_civicrm,_pre ? or both?
Answers.UserDisplayName: ericG
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-27T17:41:08.760Z
Answers.Text: submission_presave
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-29T18:43:34.460Z
Answers.Text: thanks for pointing that out
Answers.UserDisplayName: ericG
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-28T19:06:02.287Z
Answers.LastActivityDate: 2019-06-28T19:06:02.287Z
Answers.UserDisplayName: ericG
Body: <p>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.  </p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>My goal is that for existing contacts, IF the user selects "Audit" for the reason field, then the membership <em>does not update</em>.  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.</p>
  
  <p>What I have tried:</p>
  
  <ul>
  <li>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.</li>
  <li>Could I do this with a webform hook?  In that case, which hook should I be looking at so that it processes <em>before</em> the webform/civicrm integration?</li>
  <li>I looked at using CiviRules, with the <a href="https://lab.civicrm.org/partners/civicoop/webform_civirules" rel="nofollow noreferrer">Webform CiviRules integration</a>, but this seems to fire after the webform is submitted.</li>
  </ul>
  
  <p>Thank you</p>
  
Tags: <webform-civicrm>
Title: Webform conditions with memberships
ThreadText: # Webform conditions with memberships
  
  (Asked by: username_0 on 2019-06-28)
  
  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](https://lab.civicrm.org/partners/civicoop/webform_civirules), but this seems to fire after the webform is submitted.
  
  Thank you
  
  **Tags:** webform-civicrm
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-06-30. Score: 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>
  
  
  ---
  
  ### Answer by username_2 on 2019-06-28. Score: 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/>
  
  > **Comments:**
  > **username_1**: Please note this hook is too late for anything webform_civicrm  
  > **username_2**: by "this hook" you mean hook_webform_submission_presave ? or hook_civicrm,_pre ? or both?  
  > **username_1**: submission_presave  
  > **username_2**: thanks for pointing that out  
  
  ---
  
  