Hi!
I'm pretty new to Drupal, but i have a task to finish using D7. I've created a custom content type and added some integer fields to it. What i'd like to do is on the node page add a plus and a minus button and whenever one of the button's pressed, add to or take away from the value of the mentioned integer field.

How can i do that?

Thanks is advance!

Z

Comments

redsd’s picture

do you want to add that button to the frontpage of the node or the backend (where you insert or update a node)?

iamzoltanvaradi’s picture

front page

redsd’s picture

You can use
hook_node_view
something like this:


function mymodule_node_view($node, $view_mode, $langcode) {

  $additional_field = l('+', '', array('query' => array('add' => '1', 'node_id' => $node->nid)) ).' '.l('-', '', array('query' => array('add' => '-1', , 'node_id' => $node->nid)) );
  $node->content['my_additional_field'] = array(
    '#markup' => $additional_field,
    '#weight' => 10,
    '#theme' => 'mymodule_my_additional_field',
  );
}

function mymodule_node_load($nodes, $types) {
  if(!empty($_GET['add']) && !empty($_GET['node_id']) ){
    $node = node_load($_GET['node_id']);
    $node->name_of_integerfield[LANGUAGE_NONE][0]['value'] += $_GET['add'];
    node_save($node);
  }
}

The code above is an example and isn't save for public use. The get values aren't checked if they are legit and can be manipulated.
But youmight get the idea. What you probally want to work towards is using ajax to make an call to a function in the background and update that integer.

The above should do the trick aswell, however the page will need to reload.