Skip Navigation

[Résolu] telephone cred field on user form (Create Free Seller Account) stopped working..

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

The issue here is that the user had a phone number field on their form. However this field stopped working.

Solution:

Upon investigating the issue I found that the user was using some custom code to format the field into a telephone number, however the code had some issues and caused the field to stop working.

The correct code can be seen below.

document.getElementsByName('wpcf-telephone')[0].addEventListener('input', function (e) {
  var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
  e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});

To get this to work for your site just replace 'wpcf-telephone' with "wpcf-myfield" where myfield is the slug of your custom field.

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.

Our next available supporter will start replying to tickets in about 1.15 hours from now. Thank you for your understanding.

Marqué : 

This topic contains 8 réponses, has 2 voix.

Last updated by michaelS-13 Il y a 2 années et 2 mois.

Assigned support staff: Shane.

Auteur
Publications
#1319247

I am trying to: submit a new seller registration form and submit a telephone number field

Link to a page where the issue can be seen:

I expected to see:

Instead, I got:

#1319335

Shane
Supporter

Languages: Anglais (English )

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

HI Michael,

Thank you for getting in touch.

Could you provide an account where I can test this our or a page where I can see this issue ?

With the limited information that was provided i'm unable to do anything at the moment.

Looking forward to hearing from you.

Thanks,
Shane

#1319431
#1319443

Shane
Supporter

Languages: Anglais (English )

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

Hi Michael,

Thank you for the credentials, however i'm not able to log in as i'm getting an invalid username message.

Could you confirm on your end that the credentials work ?

Thanks,
Shane

#1319511

Credentials Removed

#1319585

Shane
Supporter

Languages: Anglais (English )

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

Hi Michael,

The issue is being caused by the JS code here.

document.getElementById('telephone').addEventListener('input', function (e) {
  var x = e.target.value.replace(/D/g, '').match(/(d{0,3})(d{0,3})(d{0,4})/);
  e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});

Could you explain to me what this code is suppose to do ? is it suppose to format the telephone numbers?

Thanks,
Shane

#1319809

Yes. Uses regex and a javascript event listener on the form field id to reformat phone number the user sees as they are typing in the number, 4444444444 to look like:

(444) 444-4444 as they are typing.

This was always worked, and for unknown reasons, stopped.

Don't know if they are related but in our listing form, everything worked too, except now if the registered user clicks to upload an image, they are taken to the WordPress backend image uploader vs previously the upload was entirely from the front-end.
Thanks again.

#1320239

Shane
Supporter

Languages: Anglais (English )

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

Hi Michael,

Are you currently editing the form?

It seems i'm not able to edit the form as it says you are currently editing.

Please let me know.

Thanks,
Shane

#1320285

Shane
Supporter

Languages: Anglais (English )

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

Hi Michael,

I've fixed the code. Not sure how this was working before but this is the correct code.


document.getElementsByName('wpcf-telephone')[0].addEventListener('input', function (e) {
  var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
  e.target.value = !x[2] ? x[1] : '(' + x[1] + ') ' + x[2] + (x[3] ? '-' + x[3] : '');
});


Where you get the element by the name because your code was targeting the ID of the label but we needed to get the actual field.

Please let me know if this helps.
Thanks,
Shane

#1320545

My issue is resolved now. Thank you!