Custom form calls different form in modal, submit/ajax callback of second form not called I created 2 forms:
dms_gift_voucher/src/Form/GiftVoucherForm.php
  ...

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    ....
    
    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Submit'),
      '#attributes' =&gt; [
        'class' =&gt; [
          'use-ajax',
        ],
      ],
      '#ajax' =&gt; [
        'callback' =&gt; [$this, 'confirmGiftVoucher'],
        'event' =&gt; 'click',
      ],
    ];

    // Dialog box dependency
    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';

    return $form;
  }

  ...

  /**
   * Callback for opening the modal form.
   */
  public function confirmGiftVoucher(array $form, FormStateInterface $form_state) {
    $response = new AjaxResponse();

    // Get the modal form using the form builder.
    $modal_form = $this-&gt;formBuilder-&gt;getForm('Drupal\dms_gift_voucher\Form\GiftVoucherConfirmForm', $form_state-&gt;getValues());

    // Add an AJAX command to open a modal dialog with the form as the content.
    $dialog_options = [
      'width' =&gt; 'calc(100% - 20px)',
      'dialogClass' =&gt; 'modal--gift-voucher-confirm',
    ];
    $response-&gt;addCommand(new OpenModalDialogCommand($this-&gt;t('Test'), $modal_form, $dialog_options));

    return $response;
  }

dms_gift_voucher/src/Form/GiftVoucherConfirmForm.php
  ...

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $values = []) {
    ...
    
    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Confirm'),
      '#weight' =&gt; 100,
      '#attributes' =&gt; [
        'class' =&gt; [
          'use-ajax',
        ],
      ],
      '#ajax' =&gt; [
        'callback' =&gt; [$this, 'submitModalFormAjax'],
        'event' =&gt; 'click',
      ],
    ];

    // Library
    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';


    return $form;
  }

  ...

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    // Never called!
  }

  /**
   * {@inheritdoc}
   */
  public function submitModalFormAjax(array &amp;$form, FormStateInterface $form_state) {
    $response = new AjaxResponse();
    // Never called!
    return $response;
  }

The first form works correct, the submit is called, the ajax callback renders the modal with the 2nd form.
But when i submit the 2nd form, nothing happens, no submit, no ajax callback called from the 2nd form.
How can i fix this? Any suggestions.
(Every example of drupal modal forms start with a link trigger with routing, but i find it strange why this approach doesn't work).
EDIT: As suggested in the comments, routing info:
dms_gift_voucher.routing.yml
dms_gift_voucher.gift_voucher_form:
  path: '/dms_gift_voucher/form/gift_voucher'
  defaults:
    _form: '\Drupal\dms_gift_voucher\Form\GiftVoucherForm'
    _title: 'GiftVoucherForm'
  requirements:
    _access: 'TRUE'

dms_gift_voucher.gift_voucher_cofirm_form:
  path: '/dms_gift_voucher/form/gift_voucher_cofirm_form'
  defaults:
    _form: '\Drupal\dms_gift_voucher\Form\GiftVoucherConfirmForm'
    _title: 'GiftVoucherConfirmForm'
  requirements:
    _access: 'TRUE'
Since you're programmatically setting a modal with
$response-&gt;addCommand(new OpenModalDialogCommand($this-&gt;t('Test'), $modal_form, $dialog_options));

For the form that is in the modal, Drupal needs to know what URL it should post the AJAX to and be told that its an AJAX request because this only gets set automatically when the url key doesn't have a value.
  '#ajax' =&gt; [
    'callback' =&gt; [$this, 'submitModalFormAjax'],
    'event' =&gt; 'click',
    'url' = \Drupal\Core\Url::fromRoute('dms_gift_voucher.gift_voucher_cofirm_form'),
    'options' =&gt; [
      'query' =&gt; [
        FormBuilderInterface::AJAX_FORM_REQUEST =&gt; TRUE,
      ],
    ],
  ];


Side note: The above isn't needed with the HTML way of opening dialog boxes, had you done:
&lt;a class=&quot;use-ajax&quot; 
   data-dialog-options=&quot;{&amp;quot;width&amp;quot;:600}&quot; 
   data-dialog-type=&quot;modal&quot; 
   href=&quot;/dms_gift_voucher/form/gift_voucher_cofirm_form&quot;&gt;
   Should load Test webform in a Modal
&lt;/a&gt;

because it has the URL of the form and knows its an AJAX request from the class name.