Submit is not working for contact form which was embedded by AJAX I'm trying to add contact form with AJAX callback, called from another form. Form is embedding as well, but when I submit it only page is reloading and form doesn't send any data (in my case it's a contact form, and I can't see any created contact message in backoffice after submitting).

function somemodule_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $form['somefield']['widget']['#ajax'] = [
    'callback' =&gt; 'somemodule_form_conditional_ajax',
    'method' =&gt; 'html',
    'wrapper' =&gt; 'form-conditional-ajax-wrapper',
    'event' =&gt; 'change',
  ];
  $form['#suffix'] = '&lt;div id="form-conditional-ajax-wrapper"&gt;&lt;/div&gt;'  

}


function somemodule_form_conditional_ajax($form, FormStateInterface $form_state) {
  $output = [];
  $values = $form_state-&gt;getValues();
  $conditional_form_id = $values['somefield'][0]['value'];

  $contact_message = \Drupal::entityTypeManager()
    -&gt;getStorage('contact_message')
    -&gt;create([
      'contact_form' =&gt; $conditional_form_id,
  ]);

  if (!is_null($contact_message) &amp;&amp; $contact_message instanceof Drupal\Core\Entity\EntityInterface) {
    $output = \Drupal::service('entity.form_builder')-&gt;getForm($contact_message);
  }

  return $output;
}
I just had this issue myself. Try this:

use Drupal\Component\Serialization\Json;
use Drupal\Core\Render\BubbleableMetadata;

function somemodule_form_conditional_ajax($form, FormStateInterface $form_state) {
  $output = [];
  $values = $form_state-&gt;getValues();
  $conditional_form_id = $values['somefield'][0]['value'];

  $contact_message = \Drupal::entityTypeManager()
    -&gt;getStorage('contact_message')
    -&gt;create([
      'contact_form' =&gt; $conditional_form_id,
  ]);

  if (!is_null($contact_message) &amp;&amp; $contact_message instanceof Drupal\Core\Entity\EntityInterface) {
    $form = \Drupal::service('entity.form_builder')-&gt;getForm($contact_message);
    $output = render($form);

    $data = BubbleableMetadata::createFromRenderArray($form);
    $attachments = $data-&gt;getAttachments();
    $settings = '';
    if(!empty($attachments['drupalSettings'])) {
      $settings .= '&lt;script type="text/javascript"&gt;jQuery.extend(drupalSettings, ';
      $settings .= Json::encode($attachments['drupalSettings']);
      $settings .= ');&lt;/script&gt;';
    }

    $output .= $settings;
  }

  return $output;
}


The only thing I'm unsure about is if the $output requires an array - what I've given you is a string. So it may not work.