4

Firstly, I altered the Forgot Password Form in my template.php and added the #ajax property:

// Ajaxifying the form

    $form['actions']['submit']['#ajax'] = array(
      'callback' => 'themename_user_pass_form_ajax_callback',
      'wrapper' => 'user-pass',
      'method' => 'replace',
      'effect' => 'fade',
    );

Then I created the ajax callback function:

function themename_user_pass_form_ajax_callback($form, &$form_state){

  module_load_include('inc', 'user', 'user.pages');
  return $form;

}

The form works fine in /user/password page and the ajax works too.

I want the form to appear in the front page, So in my page--front.tpl.php I added the following:

<?php 
      module_load_include('inc', 'user', 'user.pages');
      $user_pass = drupal_get_form('user_pass');
      print drupal_render($user_pass);
 ?> 

The form appears and when submitting returns with js alert

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /system/ajax StatusText: Internal Server Error ResponseText: Memory used at: devel_boot()=3.43 MB, devel_shutdown()=32.2 MB, PHP peak=32.25 MB.

Note: The ResponseText is from devel.

In my php_error log file I found this:

PHP Fatal error: Call to undefined function user_pass_validate() in /www/drupal/includes/form.inc on line 1464

The user_pass_validate() is not declared maybe module_load_include('inc', 'user', 'user.pages'); is not working with the ajax call?

1
  • I am getting the same error for forgot password activity (ajax). My forgot password link in the registration page. I noticed when I try to register with improper values and validation messages show up, then forgot password returns internal server error. This happens only in server not in my local computer. Jul 24, 2013 at 6:20

1 Answer 1

1

module_load_include() works slightly differently from your example. The first argument is the file extension, the second is the module name, and the third is the file name minus the extension.

This should work:

module_load_include('inc', 'user', 'user.pages'); 
4
  • I Change both page--front.tpl.php and template.php, Cleared all caches and runed cron. Still the same js alert with the same error appears when submitting the form and the same PHP Error. Dec 9, 2012 at 14:08
  • Sorry didn't notice that...calling drupal_get_form() directly in a template file will always cause unexpected results, try moving that logic into a MYTHEME_preprocess_page() function in your template.php file and passing the rendered form through as a variable. I just tried the module_load_include() call on a local site and that's definitely correct, so the problem might just be where your code is
    – Clive
    Dec 9, 2012 at 14:11
  • I added the following to MYTHEME_preprocess_page() module_load_include('inc', 'user', 'user.pages'); $variables['user_reset_pass'] = drupal_get_form('user_pass'); Then in my page--front.tpl.php I added the following: print drupal_render($user_reset_pass); Same problem still exist. Dec 9, 2012 at 14:25
  • 1
    This is worked at last when I include the line in hook_init. function MODULE-NAME_init() { module_load_include('inc', 'user', 'user.pages'); } Jul 24, 2013 at 7:05

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.