Finally figured out how to embed a node form via ajax the Drupal way and using the asaf module it will be ajax submitable itself.
The principle is simple you have a php function on server with some commands that it passes back, in practice this code took a while to figure out. Hope this helps someone. Here is the guide to the sort of ajax commands you can do.
My callback on server to get my form, you could use any ajax commands here and return them.
function ajax_node_forms_ajax_get_form($content_type) {
$commands = array();
$content_type = str_replace('-','_',$content_type);
global $user;
module_load_include('inc', 'node', 'node.pages');
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => $content_type,
'language' => LANGUAGE_NONE,
);
$form = drupal_get_form($content_type.'_node_form',$node);
$commands[] = ajax_command_html('#content-wrapper', render($form));
$page = array('#type' => 'ajax', '#commands' => $commands);
ajax_deliver($page);
}
Client side js that does the call on click.
$('#add-task').once('add-task', function() {
var base = $(this).attr('id');
var argument = $(this).attr('argument');
var element_settings = {
url: 'http://' + window.location.hostname + settings.basePath + settings.pathPrefix + 'anf/get/form/task',
event: 'click',
progress: {
type: 'throbber'
}
};
Drupal.ajax[base] = new Drupal.ajax(base, this, element_settings);
});
Add new comment