I was trying to load webform after page load using AJAX and after the page load the submission is broken and on submit its taking to the AJAX controller URL. I saw a similar issue in `bigpipe` but i am not using `bigpipe`

STPES:

1) After page load called a AJAX function to load the block and place it in a DIV.
2) The controller has the following code to render the block

        $build['webform'] = [
          '#type' => 'webform',
          '#webform' => $webform_id,
        ];

        $rendered = \Drupal::service('renderer')->renderRoot($build);
        return new JsonResponse($rendered);

3) On submit the submission is taking to the AJAX controller path used to load the block and submission broken

Comments

santhosh.fernando created an issue. See original summary.

jrockowitz’s picture

Status: Active » Closed (outdated)
The Webform module's issue queue is for bugs, feature requests, and planning. Please post general support questions to Drupal Answers. You can also ask questions or help answer questions on the #webform channel on Drupal Slack.

This is an ajax and custom code issue. A form when rendered will automatically use the current URL's path. You probably need to alter the form's action attribute. You could also look into the '_wrapper_format' parameter. (ie /webform/contact?_wrapper_format=drupal_modal)