Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#9 | webform.webform.event_subscription.yml | 4.52 KB | adinac |
#9 | fj_event_subscription.png | 56.17 KB | adinac |
#4 | webform.webform.form_b.yml | 2.41 KB | jrockowitz |
#4 | webform.webform.form_a.yml | 2.41 KB | jrockowitz |
#4 | Form A and Form B.png | 93.34 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House 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 CreditAttribution: mvantuch as a volunteer 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 CreditAttribution: jrockowitz as a volunteer and at The Big Blue House 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 CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #6
mvantuch CreditAttribution: mvantuch as a volunteer commentedMy bad. I've tested it with the latest beta6 and issue is now resolved. Sorry for wasting your time.
Comment #7
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedYou did not waste my time. There was definitely some underlying issues that needed to be fixed.
Comment #9
adinac CreditAttribution: adinac as a volunteer 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 CreditAttribution: Momo4 at Ibuildings commentedI'm facing the same issue of adinac. Please re-open it.
Comment #11
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedIf you do reopen the ticket. Please fully document the steps required to reproduce the issue.
Comment #12
chrlvclaudiu CreditAttribution: chrlvclaudiu as a volunteer 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 .