How to add a drop down with option groups and option values?
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-&gt;_submitValues which is an array.