We are using Webform to display multiple forms on a single page. It all works more or less fine, but on submission, I get message from the first rendered webform. WebformSubmission is picked up by it without checking if it's related to that form or not and then it's $this->webform is used for rendering the resulting message (we use simple drupal_set_message).

I'm aware I don't really use the most standard way of rendering the webform itself:

$form = Webform::load('inquiry');
$variables['inquiry'] = \Drupal::entityTypeManager()
    ->getViewBuilder('webform')
    ->view($form);

Any ideas how to resolve this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kanei created an issue. See original summary.

jrockowitz’s picture

I don't think you can add multiple forms to a page using the webform (entity reference) field because all the request/submission handling looks at only the first webform in the field. @see \Drupal\webform\WebformRequest

You could try manually adding multiple forms to a page using the webform form element type or try multiple blocks.

$output['your_form_id'] = [
  '#type' => 'webform',
  '#webform' => 'your_form_id',
  '#default_data' => ['name' => 'Custom Name'],
];

@see https://www.drupal.org/node/2840419

mvantuch’s picture

I didn't actually use entity reference but instead I've called the code from a preprocess hook for footer region. I've tried replacing it with your suggested render array, but it doesn't really change anything in the form execution.
Submission itself seems to work just fine, there is a new submission entity created and visible from the UI on admin/structure/webform/manage/newsletter/results/submissions

My problem is with the confirmation message. I've selected to display 'confirmation type' as 'Message' but the message which is displayed is the one which is set to the first webform rather the one which was actually submitted.

jrockowitz’s picture

@kanei I can't duplicate the problem. I need some easy to follow steps that replicate this issue.

Here are the steps I attempted...

- Create Form A, which displays confirmation message 'Form A'.
- Create Form B, which displays confirmation message 'Form B'.
- Place both forms as blocks on the website
- Click 'Submit' on Form A
- Check that "Form A's" confirmation message is displayed
- Click 'Submit' on Form B
- Check that "Form B's" confirmation message is displayed

Maybe you can use my Form A and B examples with a custom hook that duplicates the problem.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)
mvantuch’s picture

My bad. I've tested it with the latest beta6 and issue is now resolved. Sorry for wasting your time.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Fixed

You did not waste my time. There was definitely some underlying issues that needed to be fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

adinac’s picture

I encountered this problem as well. I a have a list of nodes (teasers), each has the same webform rendered in the teaser display. If I submit the second webform, the first one is actually submitted and has the errors displayed (the webform uses ajax, but I don't think this is the issue). I noticed that the rendered webforms are having the same form_id.
I use 8.x-5.x

Momo4’s picture

I'm facing the same issue of adinac. Please re-open it.

jrockowitz’s picture

If you do reopen the ticket. Please fully document the steps required to reproduce the issue.

chrlvclaudiu’s picture

@Momo4 and @adinac I've opened a new ticket that's trying to fix the issue here https://www.drupal.org/project/webform/issues/2957002 .