• Resolved mika85

    (@mika85)


    I created a form to connect to my administrator area but when I filled in the wrong login credentials, I received the following error message:

    {“success”:false,”data”:{“errors”:[“Email / password is not correct”]}}

    I have implemented the procedure described on your site and placed the code in the functions.php file:
    https://fluentforms.com/docs/how-to-make-a-login-form-with-fluent-form/

    the code partially works since if I enter the correct identifiers, it works fine with the correct success message but when the identifiers are not correct this, the error message is not correct.
    I have the impression that there is a problem without the JSON formatting.

    I tested with all versions of php and with several themes and the problem is still the same.

    Can you do a test on your side and tell me if you too have this problem with a connection form with the php code in the functions.php file and tell me if you have the same problem?

    Waiting for a response from you, I wish you a nice day.

    Sincerely
    Mikael

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mika85

    (@mika85)

    add_action('fluentform_before_insert_submission', function ($insertData, $data, $form) {
    
        if($form->id != 5) { // 8 is your form id. Change the 4 with your own login form ID
            return;
        }
        $redirectUrl = home_url(); // You can change the redirect url after successful login
    
        if (get_current_user_id()) { // user already registered
            wp_send_json_success([
                'result' => [
                    'redirectUrl' => $redirectUrl,
                    'message' => 'You are already logged in. Redirecting now...'
                ]
            ]);
        }
    
        $email = \FluentForm\Framework\Helpers\ArrayHelper::get($data, 'email'); // your form should have email field
        $password = \FluentForm\Framework\Helpers\ArrayHelper::get($data, 'password'); // your form should have password field
    
        if(!$email || !$password) {
            wp_send_json_error('Please provide an email and password');
        }
    
        $user = get_user_by_email($email);
        if($user && wp_check_password($password, $user->user_pass, $user->ID)) {
            wp_clear_auth_cookie();
            wp_set_current_user($user->ID);
            wp_set_auth_cookie($user->ID);
            /* user is not logged in.
            * If you use wp_send_json_success the the submission will not be recorded
            * If you remove the wp_send_json_success then it will record the data in fluentform
            * in that case you should redirect the user on form submission settings
            */
            wp_send_json_success([
                'result' => [
                    'redirectUrl' => $redirectUrl,
                    'message' => 'You are logged in, please wait while you are being redirected.'
                ]
            ]);
        } else {
            wp_send_json_error('Identifiant ou mot de passe incorrecte');
        }
    }, 10, 3);
    

    Finally I found this code and it works very well

    Plugin Support Abul Khoyer

    (@hellokhoyer)

    Hello @mika85,

    Sorry for delayed response. Glad you managed to solve the issue.

    Thank you and have a good day.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘login form error message’ is closed to new replies.