Answers.Body: <p>I believe you cannot set id to a button using php however you can define your own class for the button and use JS to set the id for that class.</p>
  
  <p>Here is the snippet to add class for button</p>
  
  <pre><code>$this-&gt;addButtons([[
    'type' =&gt; 'next',
    'name' =&gt; E::ts('Next'),
    'isDefault' =&gt; TRUE,
    'class' =&gt; 'custom_class', //adding class for button
  ));
  </code></pre>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T17:21:18.850Z
Answers.Text: I want to set a id attribute. Eg <button id="next" />
Answers.UserDisplayName: deepak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T17:48:22.277Z
Answers.Text: Yes, But you cannot add id through php it allows you to add class. You can use class in JS to set id for the button $('. custom_class').attr('id', 'next');
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-26T12:11:17.417Z
Answers.Text: I tried it but not working.
Answers.UserDisplayName: deepak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-24T11:18:46.433Z
Answers.LastActivityDate: 2019-01-24T11:18:46.433Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I am creating a button using php pear.</p>
  
  <blockquote>
    <p>Button (php code)</p>
  </blockquote>
  
  <pre><code> $this-&gt;addButtons(array(
    /**
     * Array for 'next' button
     */
      array(
      'type' =&gt; 'next',
      'name' =&gt; E::ts('Next'),
      'isDefault' =&gt; TRUE,
    ));
  </code></pre>
  
  <blockquote>
    <p>Template code</p>
  </blockquote>
  
  <pre><code>&lt;div class="crm-submit-buttons"&gt;
   {include file="CRM/common/formButtons.tpl" location="bottom"}
  &lt;/div&gt;
  </code></pre>
  
  <p>I want to add a id attribute to that </p>
  
Tags: <extension><php><smarty>
Title: How to set a id attribute to button?
ThreadText: # How to set a id attribute to button?
  
  (Asked by: username_0 on 2019-01-23)
  
  I am creating a button using php pear.
  
  > Button (php code)
  
  ```
   $this->addButtons(array(
    /**
     * Array for 'next' button
     */
      array(
      'type' => 'next',
      'name' => E::ts('Next'),
      'isDefault' => TRUE,
    ));
  
  ```
  
  > Template code
  
  ```
  <div class="crm-submit-buttons">
   {include file="CRM/common/formButtons.tpl" location="bottom"}
  </div>
  
  ```
  
  I want to add a id attribute to that
  
  **Tags:** extension, php, smarty
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-24. Score: 5 | Accepted answer
  
  I believe you cannot set id to a button using php however you can define your own class for the button and use JS to set the id for that class.
  
  Here is the snippet to add class for button
  
  ```
  $this->addButtons([[
    'type' => 'next',
    'name' => E::ts('Next'),
    'isDefault' => TRUE,
    'class' => 'custom_class', //adding class for button
  ));
  
  ```
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: I want to set a id attribute. Eg <button id="next" />  
  > **username_1**: Yes, But you cannot add id through php it allows you to add class. You can use class in JS to set id for the button $('. custom_class').attr('id', 'next');  
  > **username_0**: I tried it but not working.  
  
  ---
  
  