I planning to add a drop down button with option groups and option values.

This is my code

$form->add('select', 'a', ts('a'),
              '1' => ts('value 1'),
              '2' => ts('value 2')

Is there any efficient method to do it? Also i want to capture the option value and save it to a variable in order to save it in the database. I have tried $form->getvalue('a'), but didn't work. Much appreciate if someone could help me to solve this.

1 Answer 1


If it's a setting for your extension, then take a look at the settings framework: https://docs.civicrm.org/dev/en/latest/framework/setting/#creating-a-new-setting-in-an-extension

If you're modifying a form, then you can get the value when the person submits the form using hook_postProcess: https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess. One way it to use $form->_submitValues which is an array.

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.