Answers.Body: <p>Use this function:</p>
  
  <p>There is a field price_ which contains the ID of the price set selected</p>
  
  <p>Iterate through price sets to find this ID, and if membership matches, use this number of terms</p>
  
  <p>Be sure to set membership type ID as $membership_type_id</p>
  
  <pre><code>                $membership_num_terms = 1;
  
                  if (isset($form-&gt;_values['fee'])) {
  
                      foreach ($form-&gt;_values['fee'] as $index =&gt; $values) {
  
                          if (isset($form-&gt;_params['price_' . $index])) {
                              $id = intval($form-&gt;_params['price_' . $index]);
                          } else {
                              $id = null;
                          }
  
                          foreach ($values['options'] as $option_index =&gt; $option_values) {
                              if (($option_index == $id) &amp;&amp; ($option_values['membership_type_id'] == $membership_type_id)) {
                                  $membership_num_terms = $option_values['membership_num_terms'];
                              }
                          }
                      }
                  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-21T01:10:50.073Z
Answers.LastActivityDate: 2017-04-21T01:10:50.073Z
Answers.UserDisplayName: Adam
Body: <p>I have a price set which has the same membership with different terms i.e. 1 year, 2 year, etc.</p>
  
  <p>When using the x_civicrm_postProcess($formName, &amp;$form) hook, I can't find the term selected in the $form dump data. I need this term for a custom calculation. How do I retrieve this value from this $form when using this hook?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-04-20T14:15:59.200Z
Comments.Text: Can find the value of price group terms with:
          $form->_values['fee']['31']['options']['membership_num_terms'];
  
  How do I determine what has been selected on the form, which links to the ID 31?
  
  I can see a value in the $form
        'price_31' => string '60' (length=2)
  
  Should I be looping through the $form options, seeing is a price_<id> field exists?
Comments.UserDisplayName: Adam
Tags: <civimember><forms>
Title: Detect price group term period on CRM_Member_Form_MembershipRenewal or CRM_Member_Form_Membership
ThreadText: # Detect price group term period on CRM_Member_Form_MembershipRenewal or CRM_Member_Form_Membership
  
  (Asked by: username_0 on 2017-04-20)
  
  I have a price set which has the same membership with different terms i.e. 1 year, 2 year, etc.
  
  When using the x\_civicrm\_postProcess($formName, &$form) hook, I can't find the term selected in the $form dump data. I need this term for a custom calculation. How do I retrieve this value from this $form when using this hook?
  
  **Tags:** civimember, forms
  
  > **Comments:**
  > **username_0**: Can find the value of price group terms with:         $form->_values['fee']['31']['options']['membership_num_terms'];  How do I determine what has been selected on the form, which links to the ID 31?  I can see a value in the $form       'price_31' => string '60' (length=2)  Should I be looping through the $form options, seeing is a price_<id> field exists?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-04-21. Score: 0
  
  Use this function:
  There is a field price_ which contains the ID of the price set selected
  Iterate through price sets to find this ID, and if membership matches, use this number of terms
  Be sure to set membership type ID as $membership_type_id
                  $membership_num_terms = 1;
  
                  if (isset($form->_values['fee'])) {
  
                      foreach ($form->_values['fee'] as $index => $values) {
  
                          if (isset($form->_params['price_' . $index])) {
                              $id = intval($form->_params['price_' . $index]);
                          } else {
                              $id = null;
                          }
  
                          foreach ($values['options'] as $option_index => $option_values) {
                              if (($option_index == $id) && ($option_values['membership_type_id'] == $membership_type_id)) {
                                  $membership_num_terms = $option_values['membership_num_terms'];
                              }
                          }
                      }
                  }
  
  
  ---
  
  