0

I just want to print the user registration block through my template.php file without using the Form Block or Enabling php on my site to use this code:

<?php

if(user_is_anonymous()) {  
  $form = drupal_get_form('user_register_form');
  print drupal_render($form);
}

?>

I have tried the following:

function my_template_form_alter {

      $form = drupal_get_form('user_register_form');
      print drupal_render($form);
}

I want this block to appear on my blocks administration page just like the user login block, so I can place it anywhere I like. Any help as per how to achieve this? Thanks

0

You won't need any alters. Just go to the template in which you want to place the registration form and add,

$form = drupal_get_form('user_register_form');
print drupal_render($form);

This will print the user registration form. It's always good to have a check for anonymous users as a wrapper of this output.

Edit #1 (After question update and comments) I suppose you want to create a block that will appear in your "admin/structure/block" page and you can assign the block in any desired region? - Right? I don't think your question says the same but this can be done in the following way,

  • Create a hook_block_info() & hook_block_view()
  • In the hook_block_view() assign the "content" the following,

$form = drupal_get_form('user_register_form');
$block['content'] = drupal_render($form);

I hope this can solve your problem. I haven't tested this yet!

  • Apologies, i did not add the function wrapper where this goes to, what function do i add this to? like: function my_templatename_form_alter – IT Pro Manager Apr 5 '15 at 6:44
  • no, just add this in your tpl.php file. That will do. – Aneek Mukhopadhyay Apr 5 '15 at 6:48
  • I want this block to appear as one of the blocks in my blocks administration page, so i can place it anywhere i want – IT Pro Manager Apr 5 '15 at 7:17
  • Ahh, then you should update your question. Currently it's not clear what you need to do. So please update it so that others can suggest some options too. – Aneek Mukhopadhyay Apr 5 '15 at 7:21

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.