By glennnz on
Hi
I'm using hook_nodeapi to add buttons to a node view:
<?php
function registration_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view':
if ($node->type == 'event_registration') {
$node->content['complete_registration'] = array(
'#type' => 'button',
'#value' => 'Complete registration',
'#weight' => 20,
);
$node->content['add_another'] = array(
'#type' => 'submit',
'#value' => 'Register another entrant',
'#weight' => 21,
);
}
}
}
?>
How do I get my buttons to actually do something?
Thanks
Glenn
Comments
Bump Thanks Glenn
Bump
Thanks
Glenn
Glenn
THECA Group
Bump. Is anyone ale to help
Bump.
Is anyone ale to help with this?
Thanks
Glenn
Glenn
THECA Group
I believe you can add a
I believe you can add a submit callback to your button.
ex.
When that button is press that function will be call.
Personally I would make a form with a submit callback. So I'm not really sure if the submit functions work with just a button. But you can try it.
This should help you.
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html
Eric
Thanks Eric, I'll try that. I
Thanks Eric, I'll try that.
I agree, a form would be much easier, but doesn't work for this use case.
Cheers
Glenn
--UPDATE--
Nope, can't get that to work.
Code is:
Thanks
Glenn
Glenn
THECA Group
Ever get this working?
Glenn
Did you ever get this working? I am trying to add something myself to trigger a php function, but have no idea on the creation of a module to encapsulate the code, nor what the solution to your issue above might be, so that I can add a new element to the node view that can be pressed to execute the code...
Col.
I never figured this out. I
I never figured this out.
I ended up using a link with an image.,..
Glenn
Glenn
THECA Group
Add button with computed fields
You can add a button to your node view using computed fields. The advantage is that it's fairly uncomplicated and you don't have to include code in your module.
1. Add a computed field field. 2. Add the following into the "Computed Code" field (without the php tags):
3. Don't change anything in the "Display Format" field.
Voila, here's your button. You can also call custom functions from your computed field -- the sky is the limit.
You have to call a form from
You have to call a form from hook_node_api()
Contact me to contract me for D7 -> D10/11 migrations.