autosave before post

seven2009 - June 7, 2009 - 02:24

Hello!..

I'm developing a module that creates dynamic rows, it works like the "poll module" that creates choices, but I feel stucked, when you place information into the new rows created and my module even the "poll module" cleared the text into the new rows created, I don't want to erase the info, I need to keep such info before to create a new one.

My idea is to save the node before to create the new row (using ahah).

function my_module_menu() {

$items['my_module.json/%'] = array(
'title' => 'Renglones',
'page callback' => 'my_module_item',
'access arguments' => array('access content'),
'page arguments' => array(1),
'type' => MENU_CALLBACK,
);
$items['my_module/js'] = array(
'page callback' => 'my_module_magic_row',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);

return $items;
}

// This function creates the new row but erase the text when does its job
function my_module_magic_row() {
include_once 'modules/node/node.pages.inc';
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
// Get the form from the cache.
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);

// We will run some of the submit handlers so we need to disable redirecting.
$form['#redirect'] = FALSE;

// We need to process the form, prepare for that by setting a few internals
// variables.
$form['#post'] = $_POST;
$form['#programmed'] = FALSE;
$form_state['post'] = $_POST;

// Build, validate and if possible, submit the form.
drupal_process_form($form_id, $form, $form_state);
// This call recreates the form relying solely on the form_state that the
// drupal_process_form set up.
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
// Render the new output.
$choice_form = $form['choice'];
unset($choice_form['#prefix'], $choice_form['#suffix']); // Prevent duplicate wrappers.
$output = theme('status_messages') . drupal_render($choice_form);

drupal_json(array('status' => TRUE, 'data' => $output));
}

Any idea??

Autosave
http://drupal.org/project/autosave

This is fine, I would like to learn how they did it.

Best

 
 

Drupal is a registered trademark of Dries Buytaert.