[Solved] How to allow user to do login after submission of gravity form

We can create gravity form of having any type of fields. If we want to create a login form using gravity form, then to allow user to do login , we will have to perform extra actions for it. Suppose if I have a gravity form having ID 1 and having username, email fields and login button, then I will have to perform extra actions in the gform_after_submission filter of gravity form, as :

add_action( ‘gform_after_submission_1’, ‘do_login’, 10, 2 );

function do_login( $entry, $form ) {

global $wpdb;

$user = get_user_by ( ’email’, rgar( $entry, ‘1’ ) ); // get user by email address enetered by user

$usermeta = get_user_meta($user->ID); // get user’s status

if( $user && !is_user_logged_in() && $usermeta[‘user_status’][0] != ‘1’ ) { // check if user exists and is not disabled

wp_set_current_user($user->ID, $user->user_login); // use wp_set_current_user method to set current user as logged-in user

// If there is field remember me, then use following code :

if(rgar( $entry,’3.1′) == ‘true’){

wp_set_auth_cookie( $user->ID, true ); // Set wp_Set_auth_cookie to true if user has checked to Remember me field


wp_set_auth_cookie( $user->ID);

do_action(‘wp_login’, $user->user_login); // Use wp_login action


echo __(‘You are already logged in.’,’wayblaze’);



Thus using  above wordpress login methods and gravity form filters, we can simply create a wp login form with the help of gravity form plugin.

Leave a Reply