0

I have changed a number of forms accessible by users to fit a certain style. To do this I used an #after_build function that adds prefixes and suffixes to fields, as well as a bit of javascript. This was straightforward enough(and I hope the appropriate way to do that, though I'm not sure).

However, coming upon the user edit form, it does not behave as other forms do. The default system fields such as password, locale, email, etc, cannot be reordered and I can't seem to add prefixes or suffixes to them to insert my HTML.

I have read some things about using a template for forms via hook_theme() function, however I could not get Drupal to use my template file for the user profile edit form, though it works just fine for other forms. This was a last resort, however, and I prefer other means if possible.

How do I correctly alter the layout and html of the user profile edit form? Thank you for your time.

1 Answer 1

0

The reason the template method was not working on my site was the result of a caching issue.

To use a template file for the user profile form you can put this(or find the existing implementations of the hooks) in your template.php:

function yourtheme_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  $form['#theme'] = 'user_profile_form';
}

function yourtheme_theme($existing, $type, $theme, $path){
  return array(
    'user_profile_form' => array(
      'render element' => 'form',
      'template' => 'templates/form--user_profile',
    ),
  );
}

Template file name, in this example, becomes form--user_profile.tpl.php

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.