I am trying to embed a View into a custom form which has exposed filters. However when I add the field, it causes my custom submit button not to fire at all. It doesn't even try to reload the page.

This is my View element:

    $form['view'] = [
      '#title' => 'Select Assets',
        'view'   => [
          '#type'                    => 'view',
          '#name'                    => 'media',
          '#display_id'              => 'asset_selection',
          '#embed'                   => TRUE,

And my submit function:

    $form['asset_select_submit'] = [
      '#type'                    => 'submit',
      '#name'                    => 'form_submit_custom',
      '#value'                   => $this->t('Submit'),
      '#submit'                  => ['_mymodule_submitForm'],
      '#limit_validation_errors' => [],

I have tried adding the View both this way and using views_embed_view() with no success.

Is this possible, and if so, could someone point out where I am going wrong please?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.