Reputation: 97
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.
Upvotes: 1
Views: 963
Reputation: 68
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']);
Upvotes: 2
Reputation: 631
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'];
Upvotes: 0