Form generated from form cache displays, but missing name and value attributes I'm having a problem displaying a cached multi-step form in a custom module which generates custom entities.


After two steps, the form posts to an external URL (action changed with hook_form_form_id_alter).
If the external URL returns errors, the form is pulled from cache with form_get_cache() and displayed using drupal_render().
Form displays okay, but field elements are missing name and value attributes.
Printing the form object retrieved from cache shows expected values (#entity, fields, and user input associated with fields).

  $form_state = array(
    'submitted' =&gt; FALSE,
    'rebuild' =&gt; FALSE,
    'cache' =&gt; TRUE,
  );

  $form = form_get_cache($form_build_id, $form_state);

  $output = drupal_render($form);



I suspect that I need to rebuild $form_state input/values or am missing a form rebuild step.
Figured it out. Use form_get_cache() to get the cached entity, throw that into $form_state, and then use drupal_build_form() to put it together again.

    $form_state = array(
        'submitted' =&gt; FALSE,
        'rebuild' =&gt; FALSE,
        'cache' =&gt; TRUE,
    );

    // Pull the entity object from cache.
    $cached_form = form_get_cache($form_build_id, $form_state);
    $myentity = $cached_form['#entity'];

    $form_state['myentity'] = $myentity;
    $output = drupal_build_form('myentity_form', $form_state);