Hi all,
I have a situation where I need a function defined in the Drupal.theme to fire the node form submit. Wondering if anyone can steer me in the right direction.
This is what I'm doing:
My module provides a custom content type with title and body. After creating a node of this type you can edit the node and in addition to title and body fields there is a flash movie that will do various things, interacting with the database via amfphp remoting. When the user is done editing using the flash movie, I want to submit the form by clicking a button within flash. Calling a javascript function is not a problem; I already have this hooked up using actionscript ExternalInterface to call Drupal.theme.('myFunction'), question is, what can I do to get this javascript function to kick off the form submit?
I have tried to define a hook_menu MENU_CALLBACK that refers to a php function as the page callback, like mymodule_node_form_submit, but I can't get this to successfully complete from the javascript function.
Also the normal submit button looks like this now, after setting access to 0. Should I add an #ahah to this perhaps?
[buttons] => array (
[submit] => array (
[#type] => [submit]
[#access] => [0]
[#value] => [Save]
[#weight] => [5]
[#submit] => array (
[0] => [node_form_submit]
)
)
Comments
on further consideration..
Over a piece of pecan pie I realized I was overthinking this...
$('#node-form').submit() in Drupal.theme.prototype.myfunction does the trick!
But what about this:
[delete] => array (
[#type] => [submit]
[#value] => [Delete]
[#weight] => [15]
[#submit] => array (
[0] => [node_form_delete_submit]
)
)
I notice that node_menu has this menu callback:
$items['node/%node/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('node_delete_confirm', 1),
'access callback' => 'node_access',
'access arguments' => array('delete', 1),
'file' => 'node.pages.inc',
'weight' => 1,
'type' => MENU_CALLBACK);
Maybe I should put the nid in Drupal.settings and call location.replace with node/%node/delete'?
Or check out
Or check out http://drupal.org/project/services
excellent point...
I'm already using that module for some other stuff, and I'm going to use it with the amfphp module to manage the custom database stuff for this content type, but I was trying to not replicate the title and body fields in my flash movie, just leave them as is.
This seems to do the trick for delete:
in mymodule.module:
$settings['tpForm'] = array(
'deleteurl' => base_path().'node/'. $node->nid .'/delete',
);
drupal_add_js($settings, 'setting');
in mymodule.js:
Drupal.theme.prototype.eiTpDelete = function() {
var url = Drupal.settings.tpForm.deleteurl;
window.location = url;
}
Of course, in the time it took me to sort this out, I probably could have built those form fields in flash.. :-\