Answers.Body: <p>It should work using the following format<br/></p>
  <pre><code>$this-&gt;add('select', [YOUR CODE HERE] array('multiple' =&gt; TRUE, 'class' =&gt; 'crm-select2'));
  </code></pre>
  <p><a href="https://docs.civicrm.org/dev/en/latest/framework/quickform/entityref/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/quickform/entityref/</a><br/>
  <a href="https://select2.org/" rel="nofollow noreferrer">https://select2.org/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-29T06:31:32.847Z
Answers.LastActivityDate: 2021-05-29T06:31:32.847Z
Answers.UserDisplayName: Guitarman
Body: <p>I have a simple quickform --</p>
  <pre><code>    $this-&gt;add('text','trial_number','Trial Number',TRUE);
      $this-&gt;add('date','Trial_Date',ts('Trial Date'),CRM_Core_SelectValues::date(NULL, 'Y M d',15,1) );
      $this-&gt;addEntityRef('judge',ts('Assigned Judge'));
      $this-&gt;add('advmultiselect','started_components','Started Components',$this-&gt;getOptions(&quot;regComponents&quot;),FALSE);
      $this-&gt;add('advmultiselect','advanced_components','Advanced Components',$this-&gt;getOptions(&quot;regComponents&quot;),FALSE);
      $this-&gt;add('advmultiselect','excellent_components','Excellent Components',$this-&gt;getOptions(&quot;regComponents&quot;),FALSE);
      $this-&gt;add('checkbox','elite_offered','Elite Offered',FALSE);
      $this-&gt;add('advmultiselect','games_components','Games Components',$this-&gt;getOptions(&quot;gameComponents&quot;),FALSE);  
  </code></pre>
  <p>However, the advmultiselect fields I would like to use select2 for multiple selections of the options.  I have searched, and searched, yet cannot find any examples as to the format of the select2 add.  The options are straight forward - all in a function called getOptions().  The advmultiselect works, but well, that's just ugly.</p>
  <p>What is the format of the add('select2'.... and what attributes can I set?</p>
  <p>Thanks
  Norm</p>
  
Tags: <php><forms><select2>
Title: Select2 in php forms?
ThreadText: # Select2 in php forms?
  
  (Asked by: username_0 on 2021-05-29)
  
  I have a simple quickform --
  
  ```
      $this->add('text','trial_number','Trial Number',TRUE);
      $this->add('date','Trial_Date',ts('Trial Date'),CRM_Core_SelectValues::date(NULL, 'Y M d',15,1) );
      $this->addEntityRef('judge',ts('Assigned Judge'));
      $this->add('advmultiselect','started_components','Started Components',$this->getOptions("regComponents"),FALSE);
      $this->add('advmultiselect','advanced_components','Advanced Components',$this->getOptions("regComponents"),FALSE);
      $this->add('advmultiselect','excellent_components','Excellent Components',$this->getOptions("regComponents"),FALSE);
      $this->add('checkbox','elite_offered','Elite Offered',FALSE);
      $this->add('advmultiselect','games_components','Games Components',$this->getOptions("gameComponents"),FALSE);  
  
  ```
  
  However, the advmultiselect fields I would like to use select2 for multiple selections of the options. I have searched, and searched, yet cannot find any examples as to the format of the select2 add. The options are straight forward - all in a function called getOptions(). The advmultiselect works, but well, that's just ugly.
  
  What is the format of the add('select2'.... and what attributes can I set?
  
  Thanks
  username_0
  
  **Tags:** php, forms, select2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-05-29. Score: 1 | Accepted answer
  
  It should work using the following format
  
  ```
  $this->add('select', [YOUR CODE HERE] array('multiple' => TRUE, 'class' => 'crm-select2'));
  
  ```
  
  <https://docs.civicrm.org/dev/en/latest/framework/quickform/entityref/>  
  <https://select2.org/>
  
  
  ---
  
  