Hello,

I'm using signup and webform in conjunction and would like to hide the webform unless the user is signed up for the node but I couldn't find any variables that would let me know if the user is signed up.

Here's what I have so far in my node.tpl.php


<?php global $user; if ($node->signup == 1) { ?><?php if($node->signup_status == 1) {
	
	print "<style> #webform-client-form-$nid{ display: none; }</style>";}
	else{ print "";}
	?><?php }?>

The above almost works but when the signup_status == 0 then everyone can see the webform, I need help with the else condition. I think I need a condition that will do something like this <?php if (($comment->uid==$user->uid) || ($user->uid == $node->uid)) : ?><?php print "<h1>Yes</h1>"; ?><?php endif; ?>. I used this for comments so that owners of the content could see all the comments and only users could see their own comments. If there was a way to do this for signups I would be all set.

Thank you for building this great module.

Comments

stborchert’s picture

Hi.
$node->signup_status is an indicator for signups closed/open. E.g. a value of "1" implies signups are possible on this node, a value of "0" implies that signups are closed.

If you want to determine the signup status for a user you need a more complex construct:

function user_is_signed_up($node) {
  // Check if signup is enabled for this node.
  if ($node->signup == 0) {
    return FALSE;
  }
  global $user;
  // See if the user is already signed up for this node.
  $result = db_query("SELECT signup_time, form_data FROM {signup_log} WHERE uid = %d AND nid = %d", $user->uid, $node->nid);
  return (db_num_rows($result) > 0);
}

Add this function into the file template.php.

Now you can check if the user is signed up easily.
Btw.: it would be better to add a class to <div id="node"> instead of inserting a <style> in your node.tpl.php:

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?><?php if (!user_is_signed_up($node)) { print ' user-not-signed-up'; } ?>">...

In your style.css you can now insert

div.user-not-signed-up #web-form... {display: none;}

hth,

 Stefan

Grimlock’s picture

Stefan! You are the greatest, thanks for your help. I just learned a lot from the code you so generously created for me.

Lee

stborchert’s picture

Status: Active » Fixed

marking this as fixed

shanefjordan’s picture

By using the display:none property, the content is still listed in the code, it is just not displayed by the browser. So, when using this make sure it really is not something a particular user should see. For instance, you would not want to use this same logic for the comments that you are referring to. If you did use this, then users would be able to view the source and see all of the comments.

- Shane

Grimlock’s picture

Ah yes thank you for shedding light on this subject Shane, this is a condition that I also was worried about as well. However my troubles are gone thanks to the helpful function Stefan provided. I award users points based on their webform submission and use a cool if condition to make sure they are signed up for the node before any points are given out.

stborchert’s picture

Probably its best to write a Mini Modul that takes this function and removes the webform with hook_form_alter().

 Stefan

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.