Skip Navigation

[Resolved] Multilanguage Registration Form

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

Problem:

The customer asked how the WordPress user "Language" field can be set through the Toolset's user form.

Solution:

Informed that there is no built-in method available in the Toolset Forms for this, so it will require some workaround and custom code.

WordPress store's the ISO language code for the user's selected WordPress admin language as a value, in the user meta field with key 'locale'.

In a user registration form, one can include a hidden generic field and fill its value with the language code of the current page's language. After that, the 'cred_save_data' hook can be used to programmatically set that selected language value into the user's 'locale' meta field:


add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($user_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==1234)
    {
        update_user_meta( $user_id, 'locale', $_POST['locale'] );
    }
}

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

https://developer.wordpress.org/reference/functions/update_user_meta/

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.67 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Meg 3 years ago.

Assisted by: Waqar.

Author
Posts
#2226679

Meg

Hi,
I have a bilingual site.
I created a registration form an I added this on two post, one for language.
In creation form I did not found site localization field.
I would like to set the value of this field to the same language of registration page, where user submit form.
In this way all automatic email communication send to the user will arrive in the correct language.
There is a hook to do this?

thank

#2226879

Hi,

Thank you for contacting us and I'd be happy to assist.

There is no built-in method available in the Toolset Forms for this, so it will require some workaround and custom code.

WordPress store's the ISO language code for the user's selected WordPress admin language as a value, in the user meta field with key 'locale'.
( ISO Language Code Table: hidden link )

In your user registration form, you can include a hidden generic field and fill its value with the language code of the current page's language. After that, you can use the 'cred_save_data' hook to programmatically set that selected language value into the user's 'locale' meta field:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/update_user_meta/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2227837

Meg

It's not very clear.
How can I get $user_id from cred_save_data
I don't see it in the Arguments

thanks

#2228585

Thanks for writing back.

The first argument "post_id", will hold the ID of the created post or the created user, depending on whether it is a post form or a user form.

For example:


add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($user_id, $form_data)
{
	// if a specific form
	if ($form_data['id']==1234)
	{
		update_user_meta( $user_id, 'locale', $_POST['locale'] );
	}
}

In this example, the code will execute for only the form with ID "1234" and get the language code value from the generic field with slug "locale" and set it for the user meta field, with the same slug/key.

#2230963

Meg

My issue is resolved now. Thank you!