In Drupal 7, customer wants to add a button to the user_profile_form. So in my custom module, I create the button and its companion callback. But while the button appears on the form, I see no evidence the callback is being fired.

function member_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "user_profile_form") {
  $form['send_reset'] = array(
          '#type' => 'button',
          '#prefix' => "<div id='reset-div'>",
          '#suffix' => "</div>",
          '#value' => "Reset member",
          '#ajax' => [
            'callback' => 'member_reset_user',
            'wrapper' => 'reset-div',
            'event' => 'submit', //click, etc
          '#weight' => -150,
          '#attributes' => array(
            'id' => array('reset-cancel')
function member_reset_user($form, &$form_state) {
  try {
    watchdog('member', 'user reset', WATCHDOG_NOTICE);
  catch (Exception $e) {
    watchdog('member', 'reset failed', WATCHDOG_ERROR);
  return $form;

The html generated by Drupal suggests a submit function.

  <div id="reset-div"><input id="reset-cancel" type="submit" name="op" value="Reset member" class="form-submit"></div>

Since I'm not creating new form elements in my callback, just issuing a custom function, I cannot see what I'm doing wrong. I've been looking at this too long.

  • I take the AJAX callback isn't invoked as and when you expect. What did you do to be sure the callback is invoked?
    – apaderno
    Apr 18, 2022 at 20:50
  • (There is a typo, in that code, and a block of code isn't where it should be. They aren't the reasons for the callback not to be invoked, but the shown code isn't what you are actually using, probably.)
    – apaderno
    Apr 18, 2022 at 20:54
  • To make it clear, since the AJAX event isn't set for that button, the default one is mousedown. The AJAX callback is only invoked on that JavaScript event.
    – apaderno
    Apr 18, 2022 at 20:58
  • @apaderno Thx for responding. First line of callback has a die() to be certain. Revising goof above. The AJAX event threw me at first, but I reviewed and added event for click, submit. Still not triggering.
    – sam452
    Apr 19, 2022 at 14:08


Your Answer

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

Browse other questions tagged or ask your own question.