powermail icon indicating copy to clipboard operation
powermail copied to clipboard

[BUGFIX] Fixes errors that occur when the same form is used multiple times on the same page

Open maechler opened this issue 7 years ago • 6 comments

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 __ttcontentuid to the form containing the content element uid
  • Checking the POST parameter __ttcontentuid in FormController->forwardIfTtContentUidDoesNotMatch and forwarding to formAction if the uids do not match
  • Checking for the correct content uid in the PrefillViewHelpers and only prefill from GET / POST variables if the content uids do match
  • Inserting the Ajax response according to the attribute data-powermail-ttcontentuid instead of data-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):

  1. The data array gets cleared when errorAction is called after the validation failed. The errorAction redirects to the referring action formAction and thus the data array is missing when formAction wants to render the template. That means that the hidden field __ttcontentuid can not be filled in correctly when there are server side validation errors.
  2. We also need this information in the PrefillViewHelpers, like this it is easily accessible. Another way would be to pass the data down from Form.html to 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.

maechler avatar Mar 12 '18 17:03 maechler

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.

einpraegsam avatar Mar 27 '18 13:03 einpraegsam

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.

maechler avatar Mar 28 '18 12:03 maechler

I think this change looks good and has been well-tested.

macjohnny avatar May 29 '18 10:05 macjohnny

any update on this?

macjohnny avatar May 01 '19 10:05 macjohnny

I recognized the same problem on a customer page. Will this be fixed in the future?

mhirdes avatar Dec 23 '19 09:12 mhirdes

@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.

maechler avatar Dec 23 '19 14:12 maechler