Hello ,I would like to know if there is a way to do the following:
I have a type of content [EVENTS], each node is created an event, in the node there is a button that calls an entity form to join.

I have to find a solution to prevent users who carried out the form when they return in the node chosen to not display the button.

I had thought of using Flags and Rules, but I'm seeing difficult.
Do you have any idea?

Comments

nevets’s picture

How are you adding the button to the viewed node?

lucavox’s picture

No I know the button to add! :-)
I would have thought to add if the php code to show or not show the button (which is a div html).
I can not understand that discriminating use, so I thought to form flag. The user submitting the form, by rule selected as the preferred node then in 'I could put in "if the node is preferred not to show the div.

nevets’s picture

Without knowing how/where you adding the button it is hard to make a concrete suggestion. It sounds like you are doing things the hard way though. There are modules for signing up/subscribing to a node. And if you just want to flag the node, you can use the flag module which can be configured so for each person it for example it might initially read "Make this a preferred event" and once flagged by the user it might read "Remove from my preferred event list"

lucavox’s picture

the function of the button in the events--node.tpl.php is:

<p align="center"><?php print t('Not yet a member at our event'); ?></p><br>
<div style="text-align: center;">  
    <form action="../eform/submit/adesioni-eventi?title_node=<?php print $node->title; ?>&nid=<?php print $node->nid; ?>" method="post">
 <button value="<?php print t('Join Us'); ?>" type="submit"><?php print t('Join Us'); ?></button>
</form></div>
<?php
	}
?>

in this way call up the form. In the entity form I created two hidden fields which are populated by the token (default value)

[current-page:query:nid]
[current-page:query:title_node]

This way I have a new submission with the fields that indicate to me that node refers the form.
Now I stopped, I occorerebbe find a solution on how to prevent (once the user has submitted the form) that the user submits again the same node

nevets’s picture

Instead of placing that in events--node.tpl.php I would place it in YOURTHEMENAME_hook_preprocess_node() something like

YOURTHEMENAME_hook_preprocess_node($variables) {
$node = $variables['node'];
$not_a_member = t('Not yet a member at our event');
$join_us = print t('Join Us');

// Determine if the user is part of the event or not 
// I am guessing that you are saving the information in a entity
// Is the "author" of the entity the current user?
//  What is the entity type?
// The following is sample code, it will need adjusting for your actual entity type and fields.
  global $user;
  if ( !user->uid ) {
    // They are not logged in, assuming we need to do nothing
    return;
  }

  $query = new EntityFieldQuery();
  $entities = $query->entityCondition('entity_type', 'YOUR_ENTITY_TYPE')
                    ->entityCondition('bundle', ' YOUR_ENTITY_BUNDLE')
                    ->propertyCondition(uid', $user->uid)   // This assume the save uid is in a property
                    ->fieldCondition('field_nid', 'value', $node->nid);   // This assumes the nid is save in a field called field_nid
   $matches = count($entities['YOUR_ENTITY_TYPE']);
   if ( $matched == 0 ) {
      // They are not signed up yet
$html =<<HTML
<p align="center">$not_a_member</p><br>
<div style="text-align: center;">  
    <form action="../eform/submit/adesioni-eventi?title_node=node->title;&nid=$node->nid" method="post">
 <button value="$join_us" type="submit">$join_ud</button>
</form></div>
HTML;
   else {
      // Already part of event
      $html = "";   // Or something like $html = t('You are already signed up for this event');
    }
    $variables['event_status'] = $html;

You will need to replace YOURTHEMENAME with the name of your theme.
And replace your current html/php in event--node.tpl.php with
<?php print $event_status; ?>

It would be a better practice to replace the inline styles (align="center" and style="text-align: center;") with css classes and use css to style

A better approach would be to implement a module that implements hook_node_view() and hook_templates().
hook_templates() to declare a custom template that will implement the chunk of html and hook_node_view() to use the template to add to $node->content. I would also use the Drupal form API instead of the hand coded form.

lucavox’s picture

Thank you so much
Now I try to implement it!

lucavox’s picture

This code http error 500 :-(

softdote’s picture

You can make a chosen button hidden or disable when the users click and finish creating an event. And at next session the button will display again.

lucavox’s picture

is this was the initial idea, but I have a condition (I think) to do so. and that's why I thought of the flag.
if you (and this I do not know how to do it) flagga the node, then the php code (for a new session on that node of the same user) hides the button (well I create an if that controls whether that node for that user was flagged)