Update entity ref field in parent form with new node created in ctools modal I have a node_add form for Foo node-type with an entity reference field to Bar node-type. I'm trying to allow users to create Bar nodes inline from the Foo create form.

So far I've been able to get the ctools modal to popup, create and process the new Bar node and dpm the new Bar-type nid. but I'm stuck on how to push that to the parent Foo form and add this new Bar node into the entity reference field.

Here's what I tried using ajax_command_append in my callback for the ctools modal, but it doesn't append the new Bar node to the entity reference field values in the parent form:

function mymodule_add_bar_callback($js = FALSE) {

ctools_include('node.pages', 'node', '');
ctools_include('modal');
ctools_include('ajax');

$node_type = 'Bar'; 
$node = (object)array(
    'uid' =&gt; $user-&gt;uid,
    'name' =&gt; (isset($user-&gt;name) ? $user-&gt;name : ''),
    'type' =&gt; $node_type,
    'language' =&gt; LANGUAGE_NONE,
);

$form_state = array(
    'title' =&gt; t('ADD A NEW BAR'),
    'ajax' =&gt; TRUE,
);

$form_state['build_info']['args'] = array($node);
$commands = ctools_modal_form_wrapper($node_type . '_node_form', $form_state);

// if the form was submitted, reload parent Event-Add form
if (!empty($form_state['executed'])) {
    $commands = array();
    $commands[] = ctools_modal_command_dismiss();
    $commands[] = ajax_command_append('#edit-field-bar-und-0-target-id', '&lt;input type="text" id="edit-field-bar-und-1-target-id" name="field_bar[und][1][target_id]" value="" size="100" maxlength="1024" value="' .  $form_state['node']-&gt;title . ' (' .  $form_state['node']-&gt;nid . ')" class="form-text required form-autocomplete" autocomplete="OFF" aria-autocomplete="list"&gt;');

    $output = $commands;
}
There are few existing modules which gives the same functionality.
 - https://www.drupal.org/project/entityconnect
 - https://www.drupal.org/project/references

If you want to handle it in custom way, fetch the field and set the default (target_id) value in the form array element and use drupal_render/drupal_render_children to convert the form element array into html and try to replace it in the front end.