Buttons on Nodes

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
glennnz's picture

I'm looking for a way to add a button to the end of a node that actually does something.

Rendering the button is easy:

<?php
function button_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch (
$op) {
    case
'view':
     
$node->content['button'] = array(
       
'#type' => 'button',
       
'#value' => t('A Button!'),
      );
    break;
  }
}
?>

The hard part is getting the button to DO something!

....

Glenn

Comments

Button Field!

Itangalo's picture

Check out the Button Field module, and also have a look at the fantastic Rules module.

//Johan Falk, NodeOne, Sweden
**
Vill du lära dig mer om Drupal? Kolla in samlingen av tips och guider!
Har du en fråga om Drupal? Missa inte FAQ-sidan på forumet!
Kolla in min senaste guide: Hundra småsteg för att självlära sig Drupal 6

Try this

rohnjeynolds's picture

Off the top of my head:

<?php
function button_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch (
$op) {
    case
'view':
     
$node->content['button'] = array(
       
'#type' => 'button',
       
'#value' => t('A Button!'),
       
'#attributes' => array('onClick' => 'alert("Hey, I do something!");');
      );
    break;
  }
}
?>

similar question....

beanerboy's picture

could you take a look at this comment and suggest something...
http://drupal.org/node/1275442
but I would want the button to appear on the node.
not in a view.