Skip Navigation

[Resolved] How to use another field as password?

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to change the password fields of a user registration form so that the passwords are visible.

Solution:
You can use some custom JS to convert the inputs from type password to type text.

The following snippet of JS works on the initial page load, and also for forms submitted via ajax if it is reloaded with any validation errors, for example:

(function ($) {
    $(document).ready(function () {
        $('input[type="password"]').attr("type", "text");
    });
 
    $(document).on('js_event_cred_ajax_form_response_completed', function(event){
        $('input[type="password"]').attr("type", "text");
    });
})(jQuery);
This support ticket is created 5 years, 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by StanleyT8485 5 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#1267429

Tell us what you are trying to do?

I want to use another field as the password when creating an account.

OR just show the password instead of ****.

The final goal here is to show the password to the user.

#1267701

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

HTML password fields don't have the option to display the characters, they are always hidden with asterisks.

To show the characters you need to change the input type from password to text.

You can only do that with JavaScript or jQuery on the front-end once the page is rendered, and you may want to include a toggle for visibility.

Something like: hidden link

#1268681

Hi Nigel,

How can we do this without the toggle? We want to show the password by default.

#1268853

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

So you can add the following custom JS to the page which will simply convert password inputs to text inputs:

(function ($) {
    $(document).ready(function () {
        $('input[type="password"]').attr("type", "text");
    });
})(jQuery);
#1270193

Hi Nigel,

It worked perfectly! At first, I got a syntax error but found out that you had to put it in the JS section of the form.

Thank you!

#1270195

My issue is resolved now. Thank you!

#1271199

Hey Nigel,

Sorry. One thing I found. If the user submit a wrong info (e.g.: an email that has already been used), the password will now be hidden after the page refresh.

How would you handle this?

#1271537

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I assume you are submitting your form with ajax rather than a page refresh.

You can use a custom JS event fired by Forms when a validation problem occurs to add the same code that converts the password inputs to text inputs, e.g.

(function ($) {
    $(document).ready(function () {
        $('input[type="password"]').attr("type", "text");
    });

    $(document).on('js_event_cred_ajax_form_response_completed', function(event){
        $('input[type="password"]').attr("type", "text");
    });
})(jQuery);
#1273051

Good work, Nigel. Thank you!