I am working on a module that adds a button to a node. It is nothing fancy, but I would like the button to take the user to a specific url when clicked. I saw a way to do that here: http://groups.drupal.org/node/35844 but it relies on Javascript to get the job done.
Is there a way to add a button to a node that will just go to a link when clicked?

Comments

dman’s picture

If you don't want to do it client-side, then you do it server-side with hook_form_alter.
Add a #type=button element, and attach a #submit callback handler to it that does what you want, eg call drupal_goto().

Or it would be easier to just make a link that looks like a button if all it does is go somewhere and doesn't actually do button processing.

jergason’s picture

That will only work for a form, right? What if I just want to add it to the node?

jaypan’s picture

hook_nodeapi() $op == 'view'. Add your button there.

Contact me to contract me for D7 -> D10/11 migrations.

da_solver’s picture

Hi,
You've referenced a thread which discusses "I'm looking for a way to add a button to the end of a node that actually does something.". Therefore, you are implying that you have some sort of specific functional requirements.

If you have specific business requirements, please post them. Take the time to detail the requirements. Please explain what "add a button to a node that will just go to a link when clicked?" means???

Finally, you have stated that you are "working on a module" . Please post your code so that we can reference the details. Please document each section and explain how it fits in to your specific functional requirement.

nevets’s picture

You can also probably simplify the problem by using a link styled as a button. That means you can do it at the theme layer, either node.tpl.php or if content specific, node-content_type.tpl.php

duckzland’s picture

+1 on this. if the button do only link to page (without querying sql) then nevets way is the fastest and easiest to do.

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

dotpex’s picture

from your module this is one way to add link

function YOUR_MODULE_preprocess_node(&$vars) {
  $vars['content'] .= l(t('My Link'),'my-link-url');
}

other way:
step 1

function YOUR_MODULE_preprocess_node(&$vars) {
  $vars['my_link'] = l(t('My Link'),'my-link-url');
}

step 2
in node.tpl.php add

  print $my_link;