Skip Navigation

[Résolu] How do I populate a custom user field with user data on registration?

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How do I populate a custom user field with user data on registration?

Solution:
You can use the Toolset Form hook cred_save_data to populate the custom user field with user email.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/how-do-i-populate-a-custom-user-field-with-user-data-on-registration/#post-1100621

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

This support ticket is created Il y a 6 années et 3 mois. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par julieP Il y a 6 années et 3 mois.

Assisté par: Minesh.

Auteur
Publications
#1100442

I have a hook that applies to a User form which automatically adds required data to a custom user field when the User registers. It looks like this:-

add_action('cred_save_data', 'ts_auto_add_usermeta_497',10,2);
function ts_auto_add_usermeta_497($new_user_id, $form_data) {

    // User Form 'Register'
    if ($form_data['id']==497)    {
	
	add_user_meta( $new_user_id, 'wpcf-custom-field-1', 'Some Text');
    }
}

I have a second custom user field (wpcf-custom-email) which is a hidden field on the registration form and needs to be populated with the User's email address once they've registered but I'm struggling to implement it.

I think it needs to happen via a cred_submit_complete hook and I've tried it like this but it doesn't work.

add_action('cred_submit_complete', 'after_save_add_usermeta_497',10,2);
function after_save_add_usermeta_497($new_user_id, $form_data) {

    // User Form 'Register'
    if ($form_data['id']==497)    {
	
	// get user email
        $email = $user_info->user_email; 
   
        //update usermeta
        add_user_meta( $new_user_id, 'wpcf-custom-email', $email);
    }
}

Can you see what's wrong please?

#1100621

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - can I have a URL of page where you added the registration form?

Follwoing code - should work.

function ts_auto_add_usermeta_497($new_user_id, $form_data) {
 
    // User Form 'Register'
    if ($form_data['id']==497)    {
     
    add_user_meta( $new_user_id, 'wpcf-custom-field-1', 'Some Text');
    update-user_meta( $new_user_id, 'wpcf-custom-email', $_POST['form-email-field']);
    }
}

Where:
- Replace form-email-field with field name which holds email.

#1101281

Hi Minesh

Thank you, that worked!! Great job