Skip Navigation

[Closed] automatically log in user on cred registration form submit

This support ticket is created 2 years, 10 months 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Shane 2 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#2286665

Like other users before, Im trying to automatically log in the user after submitting cred registration form.
After following similar threads on this forum, I have the following:

add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
if ( 64710 == $form_data['id'] ) { // Edit as required
if ( !empty( $_POST['user_email'] ) && !empty( $_POST['user_pass'] ) ) {
$user_login = explode("@",$_POST['user_email']);
// get the user credentials from the $_POST object
$user = array(
'user_login' => $user_login[0],
'user_password' => $_POST['user_pass'],
'remember' => true
);
$login = wp_signon( $user, false );
if ( is_wp_error($login) ) {
error_log( $login->get_error_message() );
}
}
}
}

I have checked my form ID and has the necessary fields:
<div class="col-md-8">
<div class="row">
<div class="col-md-6">
<label for="%%FORM_ID%%_first_name">[cred_i18n name='user_first_name']First Name[/cred_i18n]</label>
[cred_field field='first_name' class='form-control' output='bootstrap']
</div>
<div class="col-md-6">
<label for="%%FORM_ID%%_last_name">[cred_i18n name='user_first_name']Last Name[/cred_i18n]</label>
[cred_field field='last_name' class='form-control' output='bootstrap']
</div>
<div class="col-md-6">
<label for="%%FORM_ID%%_user_email">[cred_i18n name='user_email-label']Email[/cred_i18n]</label>
[cred_field field='user_email' class='form-control' output='bootstrap']
</div>
<div class="col-md-6">
<label for="%%FORM_ID%%_user_pass">[cred_i18n name='user_pass']Password[/cred_i18n]</label>
[cred_field field='user_pass' class='form-control' output='bootstrap']
</div>

I can see that the user is being registered, but not logged in. From the error log, I can see that there is a problem with the password:
"Error: the password you entered for the username xxx is incorrect.

Any help would be greatly appreciated. Thanks.

#2286913

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for getting in touch.

Can you try using $_REQUEST for the user_pass instead of $_POST.

Please try this and let me know if the results are the same.

If it doesn't work Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please where applicable please provide me with a link to an example page where I can see the issue.

I've enabled the private fields for your next response.

Thanks,
Shane

#2287065

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

We generally don't provide support to custom coding, however based on the layout of your code it should work given that i've checked the POST request payload and saw the correct values there.
Can you disable all your non-toolset plugins and try testing it again as it appears that maybe another plugin is preventing the user from logging in.

Thanks,
Shane

The topic ‘[Closed] automatically log in user on cred registration form submit’ is closed to new replies.