The below code outputs my user registration form in a lightbox for unregistered users. I put it inside a block so I can place the output in my header region:

if (!$user->uid):

print drupal_get_form('user_register');

endif;

This is working fine.

The problem is that I need to show this lightbox every 10 minutes for as long as the user remains unregistered.

I was thinking about creating a custom module that hooks into cron (which is set to 10 minute intervals), and using the block hook, I'd create a block that I can then put in the desired region.

Something like this:

function invoke_lightbox_block($op='list', $delta=0, $edit=array()) {
 switch ($op) {
 case 'list':
 $blocks[0]['info'] = t('Lightbox Registration');
 return $blocks;
 case 'view':
 $blocks['subject'] = t('');
 $blocks['content'] = '<div id="lightboxAutoModal" style="display: none;" rel="lightmodal[|height: 200px;]">'.print drupal_get_form('user_register').'</div>';
 return $blocks;
 }
} 

This outputs the user registration form, but it strips out the surrounding div, and also doesn't put it in the desired region (puts it on top of the page above .

I feel that I am getting closer to a solution, but I am stuck for now.

If anybody can shed some light on this for me, that would be greatly appreciated. Is it possible that I am thinking about this in the wrong way?

Thanks!
-X.

Comments

graysadler’s picture

You're using the print function which will put it at the top. Try this instead:

...
$register_form = drupal_get_form('user_register');
blocks['content'] = '<div id="lightboxAutoModal" style="display: none;" rel="lightmodal[|height: 200px;]">'.drupal_render_form('user_register', $register_form).'</div>';
...

Also, I'm not sure why you're using cron to have this display every 10 minutes. Seems like you'd want to set a variable in $_SESSION of the last time it was displayed and then after 10 minutes, display it again.

Lead Developer and Founder of StreamRiot.com

x_v’s picture

Thanks for your input, I'll give that a try right now. $_SESSION is also a good idea, didn't think of that!