Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback Messages inconsistencies with multiple forms #292

Open
dadaxr opened this issue Oct 25, 2019 · 5 comments
Open

Feedback Messages inconsistencies with multiple forms #292

dadaxr opened this issue Oct 25, 2019 · 5 comments

Comments

@dadaxr
Copy link
Contributor

dadaxr commented Oct 25, 2019

The way feedback messages are coded prevent them to be used when there are multiple (bolt) forms on a page.

According to the following use case :
There is a first form on my page : the contact form.
Then a second form bellow, in the footer : the newsletter form.

If I correctly fill the 2nd form, and submit it, the feedback messages are correctly set in the code ... until the internal lifecycle event listener is triggered : When the src/extensions/vendor/bolt/boltforms/src/Submission/Processor/Redirect.php "process" function is called, the behavior is to send a redirect response (to transform the POST request in a GET request).

The problem lied here : when the new redirect request is handled, the forms are built again, starting with the first form (contact form), and the flash messages which were initially set by the 2nd form are now retrieved for the first form... (everything happen in the src/extensions/vendor/bolt/boltforms/src/Factory/FormContext.php file within the "build" function ).

A possible workarround could be to tied feedback messages to their respective form (using the form name), instead of globaly. We could then have the following structure :

[
"contact_form:debug" : [...],
"contact_form:error" : [...],
"contact_form:info" : [...],
"newsletter_form:debug" : [...],
"newsletter_form:error" : [...],
"newsletter_form:info" : [...],
...
]

the PR should be quite easy to do ... but it's a breaking change (it has an impact on templates).

what do you think ?

@jadwigo
Copy link
Collaborator

jadwigo commented Oct 29, 2019

As far as I remember the feedback messages can be overridden in the configuration for each form, similar to the redirect.

So you should be able to override the messages in the feedback form like this:

newsletter_form:
    notification:
        enabled: true
        debug: false
    feedback:
        error: "there was an error in the newsletter form"
        success: "The newsletter form was successfully submitted"
    fields:
        name:
            type: text

@dadaxr
Copy link
Contributor Author

dadaxr commented Oct 30, 2019

Indeed you can defined feedback message by form in the config file.

But the problem is not setting the feedback message. The problem is displaying the correctly defined message next to the right form in the template.

In short : with the current behavior, every form are fetching feedback message from the same variable in session. In theory It should not break because we submit only one form at once ... except when there is a redirect (which is the default case) which break that logic.

@dadaxr
Copy link
Contributor Author

dadaxr commented Oct 30, 2019

I can illustrate the problem like that :

given the following code :

{# my twig template #}
{{bolt_form("first_form")}}

{{bolt_form("second_form")}}
first_form:
    notification:
        enabled: true
        debug: false
    feedback:
        success: "The first form was successfully submitted"
     ...

second_form:
    notification:
        enabled: true
        debug: false
    feedback:
        success: "The second form was successfully submitted"
     ...

after the first page load it display something like that :

<form id="first_form">...</form>

<form id="second_form">...</form>

Then if I submit the 2nd form , it will display :

<div class="bolt-message bolt-success">The second form was successfully submitted</div>
<form id="first_form">...</form>


<form id="second_form">...</form>

Instead of :


<form id="first_form">...</form>

<div class="bolt-message bolt-success">The second form was successfully submitted</div>
<form id="second_form">...</form>

@bobdenotter
Copy link
Member

the PR should be quite easy to do ... but it's a breaking change (it has an impact on templates).

If you can spare the time to do a PR, that'd be welcome. I don't mind a major version bump for this! :-)

@SantinoPetrovic
Copy link

Hi!
Anyone came up with a work around for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants