This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 7 replies, has 2 voices.

Last updated by carstenD-7 5 months, 4 weeks ago.

Assigned support staff: Bruno.

Author Posts
April 11, 2019 at 2:42 pm #3589167

carstenD-7

I am trying to:
Redirect user to a confirmation/receipt page (Set by user in ACF field) after submitting a form. The redirection part is done via this codes:

header("Location: {$redirectUrl}");

Also the confirmation email that was sent to the user's inbox is also english, when it should be Chinese.

Only on mobile devices it happens, on Desktop it's working fine.

Link to a page where the issue can be seen:
From a Chinese version of the contact page, hidden link

I expected to see:
The chinese confirmation page
hidden link

Instead, I got:
The default international confirmation page
hidden link

April 12, 2019 at 12:06 am #3593361

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. If this is working on the PC but not on the mobile, it might be the cache of your mobile.

Have you tried clearing the cache of your mobile device? Have you tested this from other devices to know if the problem is the same?

If the problem persists, can you please elaborate a little more so I can better understand? Sometimes screenshots illustrating what you mean may go a long way to clarify what words fail to transmit so if you like make use of "upload an image" below the comment area.

Thank you.

April 12, 2019 at 1:31 pm #3599479

carstenD-7

I have cleared cache data storage of my mobile device' browser (chrome), and the issue still persists.

My colleagues reported that they replicated the issue on iPhones.

The screenshot won't do much, I would recommend that you test this chinese contact page on a mobile device to see and feel the issue:
hidden link

You need to submit the form, and should expect a confirmation page.

The issue is that on mobile, the contact form when submitted it should redirect to the confirmation page which is this:
hidden link

But somehow its falling back to english language.

April 12, 2019 at 1:43 pm #3599677

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

From the test I did right now, it seems that even on the computer this is redirecting to the English page.

I'll need to request temporary access (wp-admin and FTP) to your site - preferably to a test site where the problem has been replicated if possible - in order to be of better help.

You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Note:

*** Please, can I install the Duplicator plugin (or All in One Migration) to make a copy of your site and install it on my test environment? This will help me debug the problem.

*** Note: Please make a full backup of your site.

Privacy and Security when Providing Debug Information for Support: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Thank you.

April 15, 2019 at 5:53 pm #3615571

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

Thank you. I've tried downloading your website, but it seems that WP Engine does not allow the use of Duplicator. That way, I copied only your theme to look at.

I believe the problem is in the "/coro/inc/forms/Helper.php" file, at line 147:

$siteHome = site_url();

By default, WPML does not filter the "site_url" function and uses the site's default URL. Perhaps the problem can be solved by changing the "site_url" function to "home_url" that is filtered by WPML, including the language code.

This seems to have worked in your development environment. Please, could you check?

Thank you.

April 16, 2019 at 10:46 am #3621093

carstenD-7

I did the change, but its still not working for me. I have uploaded a screen record video file here hidden link

Can you check if these lines (starts on line #3) on "/coro/inc/forms/forms.php" has something to do with it?

if (function_exists('icl_object_id')) {

	add_filter('acf/settings/default_language', 'my_acf_settings_default_language');
	function my_acf_settings_default_language( $language ) {
		return 'en';
	}

	add_filter('acf/settings/current_language', 'my_acf_settings_current_language');
	function my_acf_settings_current_language( $language ) {
		return ICL_LANGUAGE_CODE;
	}
}

I used those codes above because I had some issues where the ACF "options" field group is returned in english language always despite of what language is current. But when I inserted those codes it worked, at least on Desktop.

It's also important to know that it is not only the redirect issue, there's also the same problem with the notification email being sent to the user who submits the form, and that is the email he/she receives is also in English, when it should be in the current site language he/she was in.

I highly suspect that acf values being passed to the form submit functions is the default language, but what I don't understand is why this issue is only occurring on mobile devices, I and my colleagues tested the desktop and there was no issue.

April 16, 2019 at 9:28 pm #3625711

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

The code you posted above is for the options page created with ACF: hidden link. This is not related to the form.

I've tried tracing this, but this is very much related to the code you are using.

1. You should initially follow our documentation for configuring ACF with WPML: https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/, and install ACF Multilingual, which is the bridge between ACF and WPML;

2. Within the Helper class you may need to add the language code in the "confirmationPage" method to then filter the page;

3. When a request is being made, the URL is being entered incorrectly in the form: sunquick.ebureauetdev.wpengine.com/cn//wp-admin/admin-post.php?action=request

4. Inside the "choro/inc/forms/forms.php" files, there is this call: add_action( 'admin_post_request', 'requestFormPost');.

By the name of this hook (admin_post_request), this is making a call to the "admin". Apparently, if the admin is in English, then the language code is "en" if it is in another language, then the code will be in the other language. If it is not logged in then the default language is being used ('en'). This may be causing this issue.

As you may note, this is much more about custom code than about WPML and unfortunately, custom coding is beyond the scope of our support.

We have a list of WPML hooks that can help you develop such feature, which can be seen in the links below:

- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference

If you prefer, you can contact one of our certified partners who can develop small to large features for your site: http://wpml.org/documentation/support/wpml-contractors/

Thank you.

April 17, 2019 at 12:06 pm #3630461

carstenD-7

My issue is resolved now. Thank you!

Your insights gave some hints on how to solve the issue.

The form is built from the Options Page (a ACF field group), and editors can change all the inputs or form settings per language. So it was important that the ACF values being returned are correct for that current language of the frontend.

And the main issue is when using the action hook "admin_post_xxxx", it has no knowledge of what was the language in the frontend when the user submits the form.

So I thought about adding this hidden input to the form:

<input type="hidden" name="lang" value="<?php echo ICL_LANGUAGE_CODE; ?>">

That takes the current language of the frontend from where the user submits the form.

And then in the "admin_post_xxxx" callback I retrieved it:

if (function_exists('icl_object_id')) {
       add_filter('acf/settings/current_language','my_acf_settings_current_language_request');
		function my_acf_settings_current_language_request( $language ) {
			return $_POST['lang'];
		}
	}
	
// Now we can get the correct translated ACF fields values for the forms
$forms = get_field('site_forms', 'option');

And that pretty much solves the issue.