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?
Comments
Comment #2
jrockowitz commentedI 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.
@see https://www.drupal.org/node/2840419
Comment #3
mvantuch commentedI 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.
Comment #4
jrockowitz commented@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.
Comment #5
jrockowitz commentedComment #6
mvantuch commentedMy bad. I've tested it with the latest beta6 and issue is now resolved. Sorry for wasting your time.
Comment #7
jrockowitz commentedYou did not waste my time. There was definitely some underlying issues that needed to be fixed.
Comment #9
adinac commentedI 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
Comment #10
Momo4 commentedI'm facing the same issue of adinac. Please re-open it.
Comment #11
jrockowitz commentedIf you do reopen the ticket. Please fully document the steps required to reproduce the issue.
Comment #12
chrlvclaudiu commented@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 .