my custom form is working well. but when i want to call my custom form (in a custom mudule) via AJAX, the form tag is somehow not finished or broken.

<form class="myform" data-drupal-selector="myform" action="form_action_p_pvdeGsVG5zNF_XLGPTvYSKCf43t8qZYSwcfZl2uzM" method="post" id="myform" accept-charset="UTF-8">

instead of the form tag with all elements (data-drupal-form-fields=".....") and action="/mypage" they are all missing.

do i miss something when i build my form or is it just an issue with the core form api?


i found the part why its broke:

    class FormController extends ControllerBase

    public function createForm()
        $form = \Drupal::formBuilder()->getForm(\Drupal\is_form\Form\MyForm::class);

        // echo drupal_render($form); exit(); <--- this was before

        return $form; //<--- this renders the whole page on callback from ajax, but the form tag is well

with my echo statement only the form array is rendered, but not complete (form tag).

is there any method to render only my formfields, because the return will give me the whole page page (with wrapper header footer and sidebars).

thanks in advantage

  • You need to show us some of your code. – Jaypan Aug 24 '17 at 9:59
  • @Jaypan i updated my broken code part. – Gabbax0r Aug 24 '17 at 10:05

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.