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?

  • 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?
    – Adam
    Apr 20, 2017 at 14:15

1 Answer 1


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'];

Your Answer

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

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