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.
Asked
Active
Viewed 911 times
1

Mohanraj
- 97
- 2
- 12
-
make your context a bit clear – Fazeela Abu Zohra Feb 12 '15 at 10:41
-
@mohanraj If I got what you mean you want to get nid in $.ajax() ? – Nafscript Feb 16 '15 at 19:38
-
No, i mean to use get the value from system/ajax where my input will be content type form – Mohanraj Feb 17 '15 at 05:00
2 Answers
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