I need to have the registration forms placed on the front page of my site in there own block (similar to facebook's home page). I'm using .tpl's for each page type and am having trouble figuring out how to use template.php and take the right variables from user.module.. more importantly how to construct this into a block to be included on the front page. I'm sure this isn't all that difficult.. I'm just not too familiar with template.php and such... thank you!

Comments

Chill35’s picture

You have to place the 'User login' block, either in the Left Sidebar or right one, or in your header, or in your content area. Go to admin/build/block. As far as 'per page' visibility of this block, click on the Configure link next to the 'User login' block — on that same page. This will bring you to admin/build/block/configure/user/0. Scroll down. Look at the fieldset with title 'Page specific visibility settings'. Select this radio button: 'Show on only the listed pages.' Then, under 'Pages', write this:

<front>

Caroline
11 heavens.com

Caroline
11 heavens.com

proudleo’s picture

...on the front page- not the user login block. She wants the page that the user login block refers to when a user clicks "register for account" on the login block.

Sorry I can't help you figure it out. I'd like to know how it's done, too...lol.

Jeff Burnz’s picture

Create a new block,

title, something like "Join here"
set the input format to PHP and display where you want,

paste this code into the block and save...

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

tested on Drupal 6 only

You will need to style it to fit in the block I would think the text fields are too wide.

If you need greater control over the form, theres a really good tutorial over at nick lewis's site about dominating the user login form, that would give you some good tips how to go about 100% controlling the output and style of the form. Theres also plenty of info here about altering forms - search for drupal_get_form and hook_form_alter

joelio12’s picture

Good thinking... thats easier than I thought.

How do you find the block name/id to be used in the following code? ( as 'block_name')

<?php
$block
= module_invoke('block_name', 'block', 'view', 0);
print
$block['content'];
?>

thanks.

Jeff Burnz’s picture

where you have "block_name" should actually be the module name;

e.g.

<?php
 $block
= module_invoke('poll', 'block', 'view', 0);
print
$block['content'];
?>

you can find the ID several ways - if you view source on a page (or better still use Firebug and inspect element on a block) you'll see something like this <div id="block-user-1"> where 1 is the block ID for the user module (its actually the block ID of your user block on this site).

the other way is to hover over the configure link in block admin and view the URL in the status bar, for "Most Recent Poll" block, you'll see something like this:

admin/build/block/configure/poll/0

joelio12’s picture

What about for 'view' blocks with urls like the following:

admin/build/block/configure/views/rating

or

admin/build/block/configure/views/node_comments

...i've been trying a few different things and have yet to be successful with these.

thanks for all you're help, it's much appreciated :)

Jeff Burnz’s picture

The last argument is the delta of the block, normally a number, at first I though with Views this would be the VID (views id, look in the view_view table in the database), but it turned out the delta is the view name... e.g...

<?php
$block
= module_invoke('views', 'block', 'view', 'archive');
print
$block['content'];
?>

Note the delta is now in single quotes.

Also note that I have never had the need to do this, and I only tested this quickly on a drupal 5 install...

Alan D.’s picture

If you need to modify the globals, make sure that you restore them after you use them:

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

Otherwise you may get some real strange bugs in other areas, especially with sorting and pagination.


Alan Davison
www.caignwebs.com.au
macrodesign’s picture

thanks, i was looking for this, very useful...once again thanks.

D

bdtushar’s picture

its not working
its pringint 'ARRAY'
I m using drupal 7.10

Manuel Garcia’s picture

<?php
 
print render(drupal_get_form('user_register_form'));
?>
Malex-117’s picture

I added

<?php
 
print render(drupal_get_form('user_register_form'));
?>

to my home page and the from shows up perfectly, However, when I click the submit button, it reloads my home page but all the css is broken and the background is white. Any thoughts?