Hello
I have a submit button, which I need to wrap a div tag around it like this to it:

<div class="form-group col-sm-6">
                      <button class="..." type="submit">Send my request</button>
                  </div>

Any idea how to get this done?

Comments

sumitmadan’s picture

Status: Active » Fixed

You need to use hook_form_alter to add wrapper to any element.

sumitmadan’s picture

Priority: Critical » Normal
DanChadwick’s picture

More specifically, you can use HOOK_webform_client_form_alter or HOOK_webform_client_form_NID_alter to target more specifically webform forms or a specific webform form.

And, yes, support requests are never higher than Normal priority.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

knalstaaf’s picture

For all webforms:

function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {

    $form_structure = &$form['submitted'];

    $form['actions']['submit']['#prefix'] = '<div class="extra_div">';
    $form['actions']['submit']['#suffix'] = '</div>';    
}

For one or more specific webforms:

function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {

    if ($form['#form_id'] === 'webform_client_form_YOURWEBFORMID') {
        $form_structure = &$form['submitted'];

        $form['actions']['submit']['#prefix'] = '<div class="extra_div">';
        $form['actions']['submit']['#suffix'] = '</div>';
    }

}

(Add one of these in your template.php)

josueValRob’s picture

How can i do this for drupal 8??

naber’s picture

In drupal 9, without ['action'] i.e.

function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {

    $form_structure = &$form['submitted'];

    $form['submit']['#prefix'] = '<div class="extra_div">';
    $form['submit']['#suffix'] = '</div>';    
}

etc.