I am rendering the user profile edit form ($form_id = 'user_profile_form') on a custom tpl.php page. All the custom fields are user-defined under configuration > Account Settings > Manage Fields:

Following is the code:

<?php $form = drupal_get_form('user_profile_form');?>

<div class="some_class">
    <?php print(drupal_render($form['field_2'])); ?>
    <?php print(drupal_render($form['field_3'])); ?>
    <?php print(drupal_render($form['field_4'])); ?>
    <?php print(drupal_render($form['actions'])); ?>

All the fields are being rendered well. Even the submit and cancel buttons under the actions field are rendered BUT they are not working. Nothing happens when I click on them.

Please point out any error.


I should point out that I don't want all the form elements to be rendered, which is why I am trying to render the elements separately.

  • 2
    where are you using the form and how are you getting the $form variable? Oct 31 '13 at 8:27
  • @MohammedShameem: editing the code. Please review again. I am using the form on page--user--edit.tpl.php
    – kmdhrm
    Oct 31 '13 at 8:59
  • In a custom module, you can use hook_form_alter to unset() form elements you don't want to see. api.drupal.org/api/drupal/modules!system!system.api.php/… Oct 31 '13 at 11:55
  • @Quentin You can use unset() but you definitely shouldn't. Removing form elements can easily break the validation if submission process. The correct way to handle it is to set the element's #access property to FALSE
    – Clive
    Oct 31 '13 at 12:54
  • @Clive: I tried the exact same thing. It works for other fields but not for $form['account']. Even after setting its #access to FALSE some kind of validation is happening and it says that username password and email field must be entered and these are under $form['account'] for User Profile Form.
    – kmdhrm
    Oct 31 '13 at 13:20

Can you try to use:


remove "actions". and hide all redundant elements :)

As second approach, you can

  echo render( $form['form_id']);
  echo render( $form['form_build_id']);
  echo render( $form['form_token']);
  echo render( $form['options']['status']);

in the beginning of the template file Regards

  • Its not working. I think there is some problem with submit handler for the buttons not being invoked.
    – kmdhrm
    Oct 31 '13 at 9:59
  • Can you install XDebug and trace it with Netbeans ? Oct 31 '13 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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