1

i'm submitting a form to create node using ajax. I can able to create a node using drupal_get_form('node_form', $node) but i need the node id in response. Can anyone help me out to get the node id in ajax response after creating the node.

Mohanraj
  • 97
  • 2
  • 12

2 Answers2

2

Or you can add the hidden field to the form like this:

$form['hidden-nid'] = array(
    '#type'   => 'hidden',  
    '#value' => menu_get_object()->nid,
);  

and get the value in ajax function:

$id = intval($form_state['input']['hidden-nid']);
Ilya
  • 68
  • 9
0

In the node_form function, do something like this,

$node = menu_get_object();
$node_id = $node->nid;
$form_state['#id'] = $node_id;

In the callback function you can get it as,

$id = $form_state['id'];
Fazeela Abu Zohra
  • 641
  • 1
  • 12
  • 31