Answers.Body: <p>If it's a setting for your extension, then take a look at the settings framework: <a href="https://docs.civicrm.org/dev/en/latest/framework/setting/#creating-a-new-setting-in-an-extension" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/setting/#creating-a-new-setting-in-an-extension</a></p>
  
  <p>If you're modifying a form, then you can get the value when the person submits the form using hook_postProcess: <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postProcess</a>. One way it to use <code>$form-&gt;_submitValues</code> which is an array.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-13T20:43:42.033Z
Answers.LastActivityDate: 2020-06-13T20:43:42.033Z
Answers.UserDisplayName: Demerit
Body: <p>I planning to add a drop down button with option groups and option values.</p>
  
  <p>This is my code</p>
  
  <pre><code>$form-&gt;add('select', 'a', ts('a'),
              array(
                '1' =&gt; ts('value 1'),
                '2' =&gt; ts('value 2')
                ) 
              );
  </code></pre>
  
  <p>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 <code>$form-&gt;getvalue('a')</code>, but didn't work. Much appreciate if someone could help me to solve this. </p>
  
Tags: <profile>
Title: How to add a drop down with option groups and option values?
ThreadText: # How to add a drop down with option groups and option values?
  
  (Asked by: username_0 on 2020-06-13)
  
  I planning to add a drop down button with option groups and option values.
  This is my code
  $form->add('select', 'a', ts('a'),
              array(
                '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.
  
  **Tags:** profile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-13. Score: 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.
  
  
  ---
  
  