0

I want to add fieldset tag inside form tag. Also i want to wrap all the form element under this fieldset. I'm using the following function to change the form design and html.

MY CODE:

function change_password_form($form, &$form_state) {
  if (user_is_anonymous()) {
    return $form; // Or drupal_access_denied()?
  }
  $form['#account'] = $GLOBALS['user']; 
  $form['fieldset']['current_pass'] = array(
    '#type' => 'password',
    '#title' => t('Current password'),
    '#size' => 25,
    '#required' => TRUE,
  );
  return $form;
}

CURRENT OUTPUT :

<form action="/projects/drupal/hpedu/change-password" method="post" id="change-password-form" accept-charset="UTF-8">
<div>
<div class="form-item form-type-password form-item-current-pass">
  <label for="edit-current-pass">Current password <span class="form-required" title="This field is required.">*</span></label>
 <input type="password" id="edit-current-pass" name="current_pass" size="25" maxlength="128" class="form-text required">
</div>
<div class="form-actions"><input type="submit" id="edit-submit" name="op" value="Submit" class="form-submit"></div><input type="hidden" name="form_build_id" value="form-pGcx3HehTZlOkicX1gaBrr5eBjv8iT6iccQvCN8uXTU">
<input type="hidden" name="form_token" value="1qygden7YqhLlXvjiC8-ypYDXhOKwW_brUB4BdXlKNU">
<input type="hidden" name="form_id" value="change_password_form">
</div>
</form>

EXPECTED OUTPUT :

<form action="/projects/drupal/hpedu/change-password" method="post" id="change-password-form" accept-charset="UTF-8">
<fieldset class="myclass"> <!-- This Fieldset , which i want to add --> 
<div>
<div class="form-item form-type-password form-item-current-pass">
  <label for="edit-current-pass">Current password <span class="form-required" title="This field is required.">*</span></label>
 <input type="password" id="edit-current-pass" name="current_pass" size="25" maxlength="128" class="form-text required">
</div>
<div class="form-actions"><input type="submit" id="edit-submit" name="op" value="Submit" class="form-submit"></div><input type="hidden" name="form_build_id" value="form-pGcx3HehTZlOkicX1gaBrr5eBjv8iT6iccQvCN8uXTU">
<input type="hidden" name="form_token" value="1qygden7YqhLlXvjiC8-ypYDXhOKwW_brUB4BdXlKNU">
<input type="hidden" name="form_id" value="change_password_form">
</div>
</fieldset>  <!-- This Fieldset , which i want to add --> 
</form>

Any help would be greatly appreciated.

1 Answer 1

1

It should be something like this.

function change_password_form($form, &$form_state) {
  if (user_is_anonymous()) {
    return $form; // Or drupal_access_denied()?
  }

  $form['#account'] = $GLOBALS['user']; 

  // To make the fieldset define #type as fieldset
  $form['fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Password Info'),
    '#collapsible' => TRUE, // Added
    '#collapsed' => FALSE,  // Added
  );

  $form['fieldset']['current_pass'] = array(
    '#type' => 'password',
    '#title' => t('Current password'),
    '#size' => 25,
    '#required' => TRUE,
  );

  return $form;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.