I'm looking to insert a button into the user edit page. I've seen examples of how to edit the entirety of the user-edit page, but I want to keep everything intact and only make one small change.

Is it possible to do this without building the entire user-edit page all over again from scratch?

  • 1
    do you want to edit the user form or the actual page (from the template)? Apr 2, 2015 at 21:54
  • I want to insert a button that calls a function on click. I have it working as a custom block but would like to actually insert it into the form. If that's possible to do without editing the template that'd be great
    – Amy
    Apr 2, 2015 at 22:36

1 Answer 1


Although you could add a button into the template, this is done better with the forms api using a custom module. You can use hook_form_FORM_ID_alter to alter the user_profile_form and only make the small change you want while leaving the rest of the form untouched.

As an example, you could add a button "My cool action" to the use profile form with the following code. You just need to replace MODULE with the actual name of the module you put it in.

function MODULE_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
    $form['actions']['newaction'] = array(
        '#type' => 'submit',
        '#value' => 'My cool action'
    $form['actions']['newaction']['#submit'][] = 'my_newaction_callback';

function my_newaction_callback($form, $form_state)
    // this function is called when your button is pressed
    // do whatever you want here.

Update #2

You could place the button in the middle or top of the page using the following code and figuring out which weight places it where you want. Try a weight of 0 to have it near the middle.

$form['newaction'] = array(
    '#type' => 'submit',
    '#value' => 'My cool action',
    '#weight' => -3,
    '#submit' => ['my_newaction_callback']
  • Great it worked! Is it possible to place it somewhere in the middle of the user edit form?
    – Amy
    Apr 3, 2015 at 12:29
  • I've updated my answer to show how that's possible
    – Thomas4019
    Apr 3, 2015 at 16:27

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.