Skip to content Skip to sidebar

This thread is resolved. Here is a description of the problem and solution.

Problem:
You are using Elementor forms on a multilingual website powered by WPML and encountering issues where the form fails to submit on translated pages linked via WPML. Additionally, some global widgets created in Elementor are not rendering properly on these translated pages.
Solution:
To address the form submission issue on translated pages, follow these steps:
1. Add the following code to your functions.php file:

add_action( 'wp_ajax_elementor_pro_forms_send_form', 'wssupp_set_language_ajax_form', 9 );<br />add_action( 'wp_ajax_nopriv_elementor_pro_forms_send_form', 'wssupp_set_language_ajax_form', 9 );<br />function wssupp_set_language_ajax_form(){<br />    $id = $_POST['post_id'];<br />    $post = get_post($id);<br />    $lang = apply_filters( 'wpml_element_language_code', NULL, ['element_id' => $id, 'element_type' => $post->post_type] );<br />    $current_language = apply_filters('wpml_current_language', NULL );<br />    if ( $lang != $current_language ) {<br />        do_action( 'wpml_switch_language', $lang );<br />    }<br />}

This code ensures that the AJAX request for the form submission is processed in the correct language context.

Please note that this solution might be outdated or not applicable to your specific case. If the issue persists, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If necessary, please open a new support ticket at WPML support forum for further assistance.

50% of people find this useful.

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.

Tagged: 

This topic contains 23 replies, has 0 voices.

Last updated by oliverF-6 2 months, 2 weeks ago.

Assisted by: Dražen.

Author Posts
May 22, 2025 at 11:38 am #17061314

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

I see the video, but I am not sure if there are any difference on your live website. I have checked on staging and there it works fine.

1) I have also done next on your staging site, create new page and added form, then translated it via CTE editor and it works fine.

- hidden link

I guess the problem was in your approach, as said it will cause problems. It works fine if you translate it via recommended methods. Best would be to deleted translated pages complete from website and then re-translate via correct methods, CTE, ATE or manual.

- hidden link

Let me know if that helps.

Regards,
Drazen

May 22, 2025 at 1:18 pm #17061987

beco-treat-apsK

I’ve successfully managed to reproduce the issue and have made some progress so we can work towards a solution.

In this video, you can see the step-by-step process I followed — feel free to try and replicate it on your end:

hidden link

How should we proceed from here?

Im open to test whatever is need it, and also open to do a meeting so we can take a look closer together if you want.

May 23, 2025 at 6:21 am #17064298

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back, that is actually very helpful since at least we have now a steps to test the issue.

Unfortunately I have done same steps as you did and it works fine for me, so I still can not confirm the issue, since in almost all cases when I create a new page, or re-translate with any method it works fine:

Please check video:
- hidden link

Can you try again the same and maybe spot a difference in steps or maybe something from your side like browser addon is causing some issue on saving page?

Let me know.

Regards,
Drazen

May 23, 2025 at 8:00 am #17064763

beco-treat-apsK

Hi,

It seems you haven’t fully replicated the issue yet, so I’d like to walk you through the steps to reproduce it — although they are also shown in the video I shared earlier:
1. Create a new page in English.
2. Set the page template to “Elementor Full Width” (this was not done in your video).
3. Edit the page with Elementor and add a form widget.
4. Remove any special characters from the form, just in case.
5. Save the changes.
6. Open the page in incognito mode and test the form — it works.
7. Go back to the WordPress editor and, in the WPML panel on the right, select “WordPress Editor” > “Only this page”.
8. Choose Dutch (or any other language) and proceed to duplicate the page.
9. Click the pencil icon to edit the Dutch.
10. On the lateral wpml panel, click on "Translate independently"
11. Save page.
12. Edit with elemetnor
13. Editing the page with elementor -> remove the form from the page and drag and drop a new one.
14. Again, remove any special characters from this new form.
15. Save the page and test it in incognito mode.

Video: hidden link

Result:
The form on the Dutch page fails validation, while the form on the English page works fine.

If we unlink the translation between the two pages, both forms work perfectly. The issue only occurs when the translation is linked to the default language.

Please, I kindly ask you to review the video I shared or try to replicate the exact steps above. Based on everything I’ve tested, I strongly suspect this is related to WPML String Translation.

Thank you again for your time and dedication in helping me with this issue.

May 23, 2025 at 10:17 am #17065458

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks, I have escalated this to our 2nd tier to check and advise further.

Regards,
Drazen

May 27, 2025 at 7:33 am #17076077

beco-treat-apsK

Hello Drazen, any news?

May 27, 2025 at 8:08 am #17076160

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

our 2nd tier is working on it, I will update you soon.

Sorry for delays, it was escalated on Friday and then it was weekend, so it might takes a day or two to debug it.

Regards,
Drazen

May 27, 2025 at 11:37 am #17077926

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

please add next code to your functions.php and try again:

add_action( 'wp_ajax_elementor_pro_forms_send_form', 'wssupp_set_language_ajax_form', 9 );
add_action( 'wp_ajax_nopriv_elementor_pro_forms_send_form', 'wssupp_set_language_ajax_form', 9 );
function wssupp_set_language_ajax_form(){

	$id = $_POST['post_id'];
	$post = get_post($id);
	
	$lang = apply_filters( 'wpml_element_language_code', NULL, ['element_id' => $id, 'element_type' => $post->post_type] );

	$current_language = apply_filters('wpml_current_language', NULL );

	if ( $lang != $current_language ) {
		do_action( 'wpml_switch_language', $lang );
	}
}

It seems to a bug from our side and we will escalate developers for permanent fix.

Regards,
Drazen

May 29, 2025 at 7:49 am #17086513

beco-treat-apsK

Thank you, Drazen, for your support — we finally managed to identify the issue.

The code snippet you provided does fix the validation error.

However, please note that even with the latest plugin version 4.7.6, which I believe was intended to address this, the issue still persists. The problem is not resolved in version 4.7.6.

In the end, due to this issue, I’ve decided to change the structure and workflow of my website. I’m sharing this here in case it’s useful to anyone facing a similar situation:
• Now, only the contact pages include forms, and these contact pages are not linked as WPML translations. This avoids the validation error.
• All landing pages no longer contain forms directly. Instead, they now have buttons that link to the appropriate contact page in the desired language.

It’s not the most ideal solution, but it’s easier to manage and monitor.

All the best, and thanks again.

June 4, 2025 at 12:54 pm #17106460

oliverF-6

It works with the correct code.

The code contains a potential problem: it does not check whether $_POST[“post_id”] exists before accessing it, which can lead to a PHP error if the key is missing. In addition, the function should ensure that the inputs are validated to avoid security vulnerabilities. Here is the corrected and improved code:

add_action( “wp_ajax_elementor_pro_forms_send_form”, “wssupp_set_language_ajax_form”, 9 );
add_action( “wp_ajax_nopriv_elementor_pro_forms_send_form”, “wssupp_set_language_ajax_form”, 9 );

function wssupp_set_language_ajax_form() {
// Check if post_id is set and is a number
if ( ! isset( $_POST[“post_id”] ) || ! is_numeric( $_POST[“post_id”] ) ) {
wp_send_json_error( “Invalid or missing post ID” );
return;
}

$id = (int) $_POST[“post_id”];
$post = get_post( $id );

// Check if the post exists
if ( ! $post ) {
wp_send_json_error( “Post not found” );
return;
}

$lang = apply_filters( “wpml_element_language_code”, null, [“element_id” => $id, “element_type” => $post->post_type] );
$current_language = apply_filters( “wpml_current_language”, null );

if ( $lang && $lang !== $current_language ) {
do_action( “wpml_switch_language”, $lang );
}

// Optional: success message or additional code
}

Changes and improvements:
Checking $_POST[“post_id”]:
A check is performed to ensure that post_id exists and is a number in order to avoid errors.

If the condition is not met, an error message is returned.

Type conversion:
$id is converted to an integer with (int) to ensure that it is a valid ID.

Checking the post:
A check is performed to ensure that get_post($id) returns a post to avoid errors with invalid IDs.

Checking $lang:
It is checked whether $lang has a value before the language change is carried out to avoid unnecessary actions.

Security aspect:
Validating $_POST[“post_id”] and type conversion reduces the risk of security issues such as SQL injection or unexpected behaviour.

Error handling:
wp_send_json_error is used to provide proper feedback to AJAX requests in case of errors.

Notes:
The code assumes that the WPML plugin is active, as it uses the wpml_element_language_code and wpml_current_language filters.

If the function is used in an AJAX context, it may be useful to add a success message with wp_send_json_success if the language switch was successful.

Make sure that the action elementor_pro_forms_send_form is correct and used by the Elementor Pro form.