0

I have a custom module part of which builds a block with the login form

function my_module_block_view($delta = '') {
  switch ($delta) {
    case 'awsImage_public_info_forms':
      $user_login = drupal_get_form('user_login_block');
      $out = drupal_render($user_login);
      $block['content'] = $out;
      break;
    }
  return $block;
}

Form shows up on the page I have set the block to, BUT it will not log in. I can add and incorrect username / password and I'll get a drupal status error about the incorrect username, but when the login details are correct, it will not log in - the page will reload with "?destination=node/1137" - node/1137 is the node I am using the block on. Admin pages just show access denied.

I can log in via /user and there are no watchdog messages.

1
  • if I set the node body format to php and add: $user_login = drupal_get_form('user_login_block'); $out = drupal_render($user_login); print $out; this works... why does the form not work in the custom module block?
    – ice70
    Feb 3 '20 at 16:36
0

You shouldn't need to render the form, and this may be causing your problems. The output of drupal_get_form() is a render array, so you can use that directly. Try changing this:

$user_login = drupal_get_form('user_login_block');
$out = drupal_render($user_login);
$block['content'] = $out;

To this:

$block['content'] = drupal_get_form('user_login_block');

Also, are you doing anything else to the block with preprocessing or processing? Is the system rendering the block normally, or are you rendering the block in some different manner, with a template or something?

1
  • if I change to $block['content'] = drupal_get_form('user_login_block'); the front end just shows 'Array' and no form. There is no block pre/processing. There is a custom block.tpl.php, but is just adding a wrapper div. The theme is a custom theme using bootstrap as a parent.
    – ice70
    Feb 4 '20 at 6:50

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.