TYPO3 8.7 EXT:form - Flash messages not shown in finisher until refresh page - forms

I created a custom finisher for EXT:form. Among other things, my finisher has to show a flash message:
class CreateRequestActionFinisher extends \TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher
{
// Validations ...
$flashMessage = $this->objectManager->get(
FlashMessage::class,
'Everything is fine.',
'Thanks',
\TYPO3\CMS\Core\Messaging\AbstractMessage::OK,
true
);
$this->finisherContext->getControllerContext()->getFlashMessageQueue()->addMessage($flashMessage);
}
My problem is that, in frontend, my flash message does not appear inmediately when I send my form. When I refresh my browser page (sending my form twice), my flash message appears. ¿What can I do? Thanks.

Workaround for TYPO3 v8.7:
I think this is based on this open issue regarding caching of flash messages. As a workaround, I currently use this additional finisher (last one in finisher array) to get it working properly:
-
options:
pageUid: '1' # uid of the page with the form
additionalParameters: 'no_cache=1'
identifier: Redirect
TYPO3 v9.5.6 and newer:
I think that this problem has now been solved because of this patch and a workaround is no longer necessary.

Related

Multistep form returns to step 1 on page refresh with post data (TYPO3 9, form framework)

I am designing a multistep form with the form framework which generally works fine.
I am using a yaml form definition, the pages are defined like this:
renderables:
- identifier: page-1
label: 'Address'
type: Page
(...)
- identifier: page-2
label: 'Details'
type: Page
However, when I am on page 2 or higher and I press the reload button in my browser, all my form session data is lost and I'm sent back to page 1.
I assume it is related to trusted properties, HMAC or C-Hash values, but I don't know where to start debugging. Can someone help me getting to the source of the problem?
Maybe it's a security feature in the form framework that every post request can only be sent once. As an advanced user, however, I would expect a website to allow refreshing a form.
The URL of the form has a chash parameter.
These are the POST fields I got with Firefox dev tools:
tx_form_formframework[myform-1234][__state]
tx_form_formframework[myform-1234][__session]
tx_form_formframework[__trustedProperties]
tx_form_formframework[myform-1234][firstName]
tx_form_formframework[myform-1234][lastName]
tx_form_formframework[myform-1234][address]
tx_form_formframework[myform-1234][housenumber]
tx_form_formframework[myform-1234][zip]
tx_form_formframework[myform-1234][city]
tx_form_formframework[myform-1234][phone]
tx_form_formframework[myform-1234][email]
tx_form_formframework[myform-1234][emailrepeat]
tx_form_formframework[myform-1234][position]
tx_form_formframework[myform-1234][positionDifference]
tx_form_formframework[myform-1234][newPositionSelect]
tx_form_formframework[myform-1234][qCb6UuWPvJmAlgn3Tz]
tx_form_formframework[myform-1234][__currentPage]

EXT:Form TYPO3 form finisher settings not working

I created a contact form with an 'email to recipient'-finisher but when the user sends the form, the message "Oops, an error occurred!" show up. However, when I use 'confirmation message' as a finisher no such error shows up. The 'page redirect'-finisher also returns an error.
Do you have any ideas how to fix this? (I'm also not getting anymore detailed error information even though I have the debug mode turned on in the configuration presets..)
I had not correctly configured the 'Mail handling settings' found under 'Configuration presets' in 'Settings'. I added custom settings to write the form replies to a local file, as the website was not live and I wanted to run tests.

Drupal 7 Webform redirect

We have a Drupal 7 webform that redirects to a url upon successful submission.
What we need to do is redirect the user if they land on the same webform again and have already submitted.
Do we need a module for this, or do it programmatically?
Thanks in advance.
I looked through the webform module and didn't find any setting that will redirect the user if the user has already submitted a form, so I think you need to do it programmatically.
Note: It might be possible without a custom module by using the rules module. I haven't tried this.
To do it programmatically you could do something like below. It implements the hook_node_view() and checks if the user has already submitted anything by using the webform api function webform_get_submission_count(). (edit: the custom module in this example is called example_webform)
<?php
/**
* Implements hook_node_view().
*/
function example_webform_node_view($node, $view_mode, $langcode) {
global $user;
module_load_include('inc', 'webform', 'includes/webform.submissions');
$submission_count = webform_get_submission_count($node->nid, $user->uid);
if (!empty($submission_count) && $submission_count > 0) {
$redirect = $node->webform['redirect_url'];
drupal_goto($redirect);
}
}
As it is now it will reuse the page that is used when the form is submitted, so if you choose to do this remember to make the success page reflect this. (E.g. it would be strange for the success page to say "your post has been saved" if the user lands on it for the second time.) Or you could replace the $redirect with another page than the one from the webform setting.
Also note that the webform will still add the message "You have already submitted this form. View your previous submissions." if this is enabled.
So here is the solution that we ended up going with.
I saved the webform and made it available as a block
I created a page to hold the webform
I configured the block to appear above the page content
In the page content I put in some javascript to detect if the form element was present - if not forward to the correct url
So the webform redirects correctly upon submission(set in the webform settings), and it then redirects if the user lands back on that page and has completed the webform.

How do I correctly Implement an event on successful form Submission using Google Tag Manager and Sitecore's Web Forms for Marketers?

I am attempting to track successful form Submissions using an event in Google Analytics via Google Tag Manager. My current setup successfully tracks when users submit the form. However, the event still fires even when the form submission is invalid and does not submit (ie a user hasn't filled out all of the required fields, clicks the submit button, the form attempts to validate, but comes back to the user with errors instead of submitting). I have the Check Validation feature on my listener checked which theoretically should keep the tag from firing if the form submission is prevented, so it's not the obvious error.
The form in question is created with Sitecore's Web Forms for Marketers. Colleagues of mine have had similar unsolved issues with their WFFM forms.
This particular form is used to gate content so that only users who fill out the form will have access to the content resource. So for example if I go to www.mydomain.com/resource I will be redirected to www.mydomain.com/form where if I fill out all of my information correctly and submit it I will then be redirected to the resource that I was originally attempting to view at www.mydomain.com/resource.
Here's my setup:
Tag 1
Name: Form Submission Listener
Type: Form Submit Listener
Wait For Tags: Checked
Max Wait Time: 2000 milliseconds
Check Validation: Checked
No advanced Settings
Firing Rule: On form pages by URL
Tag 2
Name: Event Form Submission
Type: Universal Analytics
Tracking ID: UA-.....
Enable Display Advertising Features: Checked
Track Type: Event
Category: Form
Action: Submission
Label: {{Form resource URL}}
Non-Interaction Hit: False
No More Settings
No Advanced Settings
Firing Rules: {{event}} equals gtm.formSubmit
Theoretically the Check Validation check box should prevent the tag from firing if the form does not successfully submit, but in the case of this form it does not. The tag fires regardless of whether the form submits or not.
Apologies that I cannot link to the form as it is for a client and behind security.
We were able to find an answer to our question via the Sitecore forums, but I wanted to pass it along for your benefit.
From Sitecore:
The Web Forms module provides the double level validation, 1-client validation, 2-server validation.
By default, the client validation is disable for the Required Field validator. So, when you press Submit, the form posts to the server, and returns with the validation error. It's a possible reason why Google Analytics considers that as a form submit.
Find the following item in the Master database:
/sitecore/system/Modules/Web Forms for Marketers/Settings/System/System Validation/NotEmpty
Find the "Enable Client Script" checkbox and enable it.
Save and publish the item.
Check whether the issue was fixed.
This fixed the issue for all of our text based fields. It did not fix the issue for the one checkbox on the form. I've followed up with sitecore on this, but I figured that I'd update here in the meantime.
With only the checkbox remaining I was also able to use a a macro and add to my original firing rule in google tag manager so that the event would not fire if the checkbox was not checked.
I created a Custom Javascript Macro called Radio Button Checked (not sure it's the best, but it worked), and added a new condition to my original Form Submission Rule: {{Radio Button Checked}} equals true
The macro:
function() {
var radioName = "radioButtonName";
try {
var buttons = document.getElementsByName(radioName);
for (var i = 0;i < buttons.length;i++){
if(buttons[i].checked) {
return true;
}
}
} catch(e) {}
return false;
}
EDIT: Sitecore got back to me about the checkbox issue.
From Sitecore:
Currently the CheckBox field type doesn't have the client-side validation. I registered it as a bug for the WFFM module. I'll let you know as soon as it's fixed.
They let me know also that this isn't something that will be fixed near-term so I need to continue using my GTM workaround for the check box field.
The Google Chrome plugin "Tag Assistant" is super helpful in debugging these sorts of issues. It will show you what (if any) structural or implementation issues exist on a given page that might be preventing your intended tracking behavior (https://chrome.google.com/webstore/detail/tag-assistant-by-google/kejbdjndbnbjgmefkgdddjlbokphdefk?hl=en)
My gut feel is that this issue is not specifically related to WFFM, but may be due to the implementation of the Tag Manager code on the page. I seem to recall having an issue like this when the Tag Manager include code gets dumped inside the auto-generated .NET tag when using WebForms in general. Google's docs (https://developers.google.com/tag-manager/quickstart) say to put it immediately after the opening tag, and I recall that being my issue with tracking form submits.
This is all from memory, so I could be wrong, but it's something else to check.
Good luck!

Does using the action class of different module causes change in header during form submission?

I have problem with form submission to a action of different moudule, say e.g I have a module called "mymobile" from I am calling a action in module "register" which will process the registration, if there is any error in form I am setting the error messages and forwarding to "mymobile" module's page from where I called the action of "register", so it is modifying the header and my Japanese text is getting converted to some junk. Is there any way I can show error messages on my form without change of text? Any alternative for $this->forward() method? I am using symfony 1.1 and I tried $this->rediect() it will refresh the page.
Thank you in advnace