3

I am using Drupal 7.

I clicked on Structure > Block > Add Block; I filled in the block title and block description. In the block body, I put in this code.

<?php
  $_GET['q'] = 'user/register';
  print drupal_get_form('user_register');
?>

I set the text format to PHP (PHP wasn't in the drop down options of text formatting so I added PHP to it), and I clicked on save block.

The block is now created but it's just empty. I can't see any sign up form.

Can someone please put me through? I'm new to Drupal.

I just discovered that I had to activate PHP Filter in core modules (administration > modules). So when I activated PHP Filter module, the registration block I created now shows the word "Array", and also some error in the log.

Notice: Undefined index: user_register in drupal_retrieve_form() (line 764 of C:\xampp\apps\drupal\htdocs\includes\form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'user_register' not found or invalid function name in drupal_retrieve_form() (line 799 of C:\xampp\apps\drupal\htdocs\includes\form.inc).

Notice: Array to string conversion in eval() (line 3 of C:\xampp\apps\drupal\htdocs\modules\php\php.module(80) : eval()'d code).

However, the "create new account and login" menu is now showing; it is only not showing in the block I created for it. What is showing in the block is "Array"; when I click on either "register" or "log in," it takes me away from the front page (to the register page).

  • The code you used in the block did not go through. Try posting it again so others can have a look. Also, this part: "so i went to the setting to input it" isn't quite clear - did you enable the core PHP module? – Aram Boyajyan Nov 10 '13 at 15:51
  • thanks a lot. i just enabled the core PHP module and it now shows the log in menu. except that it is not showing in the block i created for it. (what is showing in the block is "Array" and when i click on either "register" or "log in" it takes me away from the homepage (to the register page) – Junior Nov 10 '13 at 17:30
  • The drupal_get_form returns Drupal renderable array as far as I remember, and this is why you see the word 'array'. Try to wrap the drupal_get_form with the render function. – rreiss Nov 10 '13 at 21:20
2

The user register form id is user_register_form. Please try it like:

$form = drupal_get_form('user_register_form');
print render($form);
| improve this answer | |
0

You should use Form Block module which provides user registration and node creation forms in blocks.

| improve this answer | |
-1

Use the following code.

print(drupal_render(drupal_get_form('user_register_form')));
| improve this answer | |
  • 1
    drupal_render() expects a variable passed by reference; you cannot use the value returned from a function, if that function doesn't return a reference. – kiamlaluno Nov 11 '13 at 13:38

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.