Quform login form example

Step 1

Add a Text element (for the Username field), a Password element and a Checkbox element (for the “Remember me” field) to the form.

Make the Username and Password elements required.

Go to the settings for the Checkbox element, set the Label to be empty and at the Options settings just have one option Remember me.

Go to Edit Form → Settings → General and turn off the Save submitted form data option.

Go to Edit Form → Settings → Style → Buttons and at the Submit button text enter the text for the submit button e.g. Login.

Go to Edit Form → Settings → Notifications and delete the Admin notification.

Go to Edit Form → Settings → Confirmations and go to the settings for the Default confirmation then at the Type option choose Reload the page, or choose Redirect to another page then choose a page to redirect to.

Step 2

Add the following code to the WordPress theme functions.php file (or create a plugin for it).

12
3456
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
add_filter('quform_post_validate_1', function (array $result, Quform_Form $form) {    $credentials = array(
        'user_login' => $form->getValueText('quform_1_3'),        'user_password' => $form->getValueText('quform_1_4'),        'remember' => $form->getValueText('quform_1_5') == 'Remember me',    );
 
    $user = wp_signon($credentials);
 
    if (is_wp_error($user)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => $user->get_error_message()
            )
        );
    }
 
    return $result;
}, 10, 2);
add_filter('quform_post_validate_1', function (array $result, Quform_Form $form) {
    $credentials = array(
        'user_login' => $form->getValueText('quform_1_3'),
        'user_password' => $form->getValueText('quform_1_4'),
        'remember' => $form->getValueText('quform_1_5') == 'Remember me',
    );

    $user = wp_signon($credentials);

    if (is_wp_error($user)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => $user->get_error_message()
            )
        );
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 3, replace the 1_3 with the Username element unique ID
  • On line 4, replace the 1_4 with the Password element unique ID
  • On line 5, replace the 1_5 with the Checkbox element unique ID, and replace Remember me with the exact option text (case sensitive)
1
2
3
4567
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function my_user_login(array $result, Quform_Form $form)
{
    $credentials = array(
        'user_login' => $form->getValueText('quform_1_3'),        'user_password' => $form->getValueText('quform_1_4'),        'remember' => $form->getValueText('quform_1_5') == 'Remember me',    );
 
    $user = wp_signon($credentials);
 
    if (is_wp_error($user)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => $user->get_error_message()
            )
        );
    }
 
    return $result;
}
add_filter('quform_post_validate_1', 'my_user_login', 10, 2);
function my_user_login(array $result, Quform_Form $form)
{
    $credentials = array(
        'user_login' => $form->getValueText('quform_1_3'),
        'user_password' => $form->getValueText('quform_1_4'),
        'remember' => $form->getValueText('quform_1_5') == 'Remember me',
    );

    $user = wp_signon($credentials);

    if (is_wp_error($user)) {
        $result = array(
            'type' => 'error',
            'error' => array(
                'enabled' => true,
                'title' => '',
                'content' => $user->get_error_message()
            )
        );
    }

    return $result;
}
add_filter('quform_post_validate_1', 'my_user_login', 10, 2);
  • On line 4, replace the 1_3 with the Username element unique ID
  • On line 5, replace the 1_4 with the Password element unique ID
  • On line 6, replace the 1_5 with the Checkbox element unique ID, and replace Remember me with the exact option text (case sensitive)
  • On line 24, replace the number 1 with the form ID
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy