Very simple question

davidzo - June 8, 2009 - 20:38

This is a very simple question and I am willing to pay $10 via PayPal for the answer because I can't find it anywhere.

How can I add a link to a node that will add a value to a field of that node when clicked?

Additional Background Info: I want to have a "add this show" link that will add a node reference to the currently logged in user's profile, but I can figure that out if I could just figure out how to add a link to a node that will add a value to a field of that node when clicked.

Try

Suede Pudding - June 9, 2009 - 00:27

Try out..

http://drupal.org/project/flag

With that you should be able to set up a bookmark type link on your show content type for any user to use.

Another way might be...

http://drupal.org/project/bookmarks

Which could do the same thing but does not use http://drupal.org/project/views.

If you need to display those flags on a user page..and not just in a menu for the user..then I would imagine that the flag module would be the way to go. Since flag use's views then you should be able to embed a view of that users flags on there profile page..you also might want to use http://drupal.org/project/content_profile and http://drupal.org/project/contemplate to give you really powerful..and semi-easy ways to manipulate what goes on a profile page.

If that helps ya out.. donate the $ to any drupal project that needs it.

Thank you for the reply :] I

davidzo - June 9, 2009 - 04:17

Thank you for the reply :]

I already tried using flags but failed because I actually need to link the 'show' nodes to the 'profile' nodes - they are both content types created to the CCK. I am going to read up on
hook_form_alter which was mentioned below and hopefully find the a solution that way.

Your help was much appreciated.

sounds like vote .. people

mm167 - June 9, 2009 - 00:20

sounds like vote ..

people vote in comments and the total (or average) vote appear in the node.

if that's u are looking for, I may provide a detail step by step guide to u.

good day.

We go the drupal way. How about you?
http://www.drupalway.com

userreference

grobemo - June 9, 2009 - 02:04

Have you thought about creating a userreference field with unlimited values in each "show" node? A little hook_form_alter work should be able to hide access to the userreference field itself and add a checkbox that, when the form is submitted, would tell Drupal whether to add the current user as another userreference.

Either way, I suppose hook_form_alter is going to be what you need, if you can't find an existing module.

Is there any way to create a

davidzo - June 9, 2009 - 04:29

Is there any way to create a nodereference (my user profiles are a content-type) through a hyperlink?

.

grobemo - June 9, 2009 - 14:59

It takes a bit of coding, but it can be done. Basically, you write a little module that contains a menu callback at a path like /favorites/add (or whatever you want). The callback should load the (user profile) node, add the nodereference to it, and save the node again.

I've done something similar, though I was saving something to a user profile. Here's a snippet, adapted from my code, that might help you.

<?php

function YOURMODULE_menu() {
 
$items = array();

 
$items['favorites/add/%'] = array(
   
'access arguments' => array('access content'),
   
'page callback'    => 'YOURMODULE_favorites_add',
   
'page arguments'   => array(2),
   
'type'             => MENU_CALLBACK,
  );

  return
$items;
}

function
YOURMODULE_favorites_add($arg) {
  global
$user;

  if (
is_numeric($arg)) {
    if (
$show_node = node_load($arg) && $show_node->type == 'show' && node_access('view',$show_node)) {
     
$user_node = // load your user profile node
     
$user_node->field_favorites[] = array('#value' => $show_node->nid); // or something like this
     
node_save($user_node);

      print
'<div class="favorites-confirm-save">'. t('@show_title has been added to your favorites.',array('@show_title' => $show_node->title) .'</div>';
      exit();
// Use exit if you want to return this via AJAX; otherwise, delete this line and replace print with return in the line above.
   
};
  }

 
// If we didn't exit above, return a 404 error (or other custom error message, if you prefer).
 
drupal_not_found();

}

?>

Finally, I'd suggest doing this by AJAX using jQuery like the following:

$('a.favorites-add').click(function() { $(this).parent().load('favorites/add/CURRENT-NODE-ID div.favorites-confirm-save'); });

That will load the div from the callback into the parent element of any link with class favorites-add when the link is clicked. You might want to do $.ajax() instead of $(this).load() to include error handling.

_

WorldFallz - June 9, 2009 - 18:40

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

 
 

Drupal is a registered trademark of Dries Buytaert.