Saltar navegación

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 support ticket is created hace 5 años, 4 meses. 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Etiquetado: 

Este tema contiene 8 respuestas, tiene 2 mensajes.

Última actualización por michaelS-13 hace 5 años, 4 meses.

Asistido por: Shane.

Autor
Mensajes
#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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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!