[BUGFIX] Fixes errors that occur when the same form is used multiple times on the same page
There are currently some issues when using the same form multiple times on the same page (tested with TYPO3 v8.7.10 and powermail v5.5.0):
- On server side validation errors, all the forms with the same uid get filled in and validated
- When the form is successfully submitted, the success message always appears in the first form
- The emails are always sent to the recipients of the first form on the page
This pull request fixes the issues the following way:
- Adding an additional hidden field
__ttcontentuidto the form containing the content element uid - Checking the POST parameter
__ttcontentuidinFormController->forwardIfTtContentUidDoesNotMatchand forwarding toformActionif the uids do not match - Checking for the correct content uid in the
PrefillViewHelpersand only prefill from GET / POST variables if the content uids do match - Inserting the Ajax response according to the attribute
data-powermail-ttcontentuidinstead ofdata-powermail-form
I am storing the data array of the current content object into GLOBALS['TSFE']->applicationData for two reasons (https://github.com/maechler/powermail/blob/develop/Classes/Controller/FormController.php#L478-L496):
- The data array gets cleared when
errorActionis called after the validation failed. TheerrorActionredirects to the referring actionformActionand thus the data array is missing whenformActionwants to render the template. That means that the hidden field__ttcontentuidcan not be filled in correctly when there are server side validation errors. - We also need this information in the
PrefillViewHelpers, like this it is easily accessible. Another way would be to pass the data down fromForm.htmlto the field templates (e.g.Input.html), but that would have a bigger impact on existing code.
If you have any suggestions to improve the code I would be happy to update the pull request.
This is really a large change in powermail. At the moment it's a missing feature to have the same form twice on the same page, even if it's possible to use multiple powermail plugins on the same page. Because it's a big change, I'm not sure if I want to implement it with the next major update or not or only if I do some small refactorings. For now: I will let this PR open. Probably some other admins can use and report feedback.
I see that this is a big change. However I think that this pull request changes as little as possible to make it work. I would be very happy if this or a similar fix finds its way into the core.
I think this change looks good and has been well-tested.
any update on this?
I recognized the same problem on a customer page. Will this be fixed in the future?
@mhirdes Applying the changes from my pull request should solve the issue, although I have not tested it with the most recent version of powermail. However it would still be nice if this fix or something similar would find its way into powermail.