Or is drupal_get_form not the right way to go about loading node forms where I want to also get the $form_state?

The reason I am asking is I would like to be able to place multiple node forms on the same page and have them editable (not in a popup) on the same form as the parent form. I have already tried inline_entity_form and that would almost work, however that module does not load the entire form inline with the rest of the parent node form. Rather it places the referenced nodes in a table that you then interact with and save separately.

1 Answer 1


When you do drupal_get_form() the form and state is cached, otherwise other Drupal form functions wouldn't be able to get it back later.

The only way I know to get it is like this:

// Get the form.
$form = drupal_get_form('my_form_id');
// Get the default form state.
$form_state = form_state_defaults();
// Get the form and form state from the cache for the form you just got.
form_get_cache($form['#build_id'], $form_state);

Since form_get_cache() returns the form also you could do the last line like this:

$form = form_get_cache($form['#build_id'], $form_state);

and it would overwrite your form with the cached one and update your form state (since $form_state is passed by reference) but in the case of calling it right after drupal_get_form() there is no need to do that.

  • Thanks for this, I was trying to access $form_state in an #upload_validators callback and there was none passed to it. The $form statement causes an infinite loop there but I don't need that anyways. I just accessed the #build_id from $_REQUEST['form_build_id']. Commented Jun 17, 2016 at 13:15
  • Crosslinking my question drupal.stackexchange.com/questions/204329/… Commented Jun 17, 2016 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.