CP Guest + javascript code for phone number

‎07-18-201307:42 AM

Hi,

Does anyone already do this kind of thing ?

In the registrer form, I would like to have a field where I can input a phone number and when I submit the form, the field is copied to an hidden field with a +41 added before the phone number (if the number begins by 07x).

Any idea where to begin ? I know a bit of javascript but not enough to do make it alone.

Re: CP Guest + javascript code for phone number

‎07-18-201305:38 PM

CPG does allow you to run custom JavaScript when the Submit button is hit. To set up this workflow, edit the self-registration register form and edit the submit field. Under the Advanced Properties, there is a field for AJAX Submit. This is where you can enter a JavaScript function name, such as "RegisterSubmit()". Next, edit the self-registration registration footer. This is where you can write your custom RegisterSubmit function.

Below is an example JavaScript function that reverses the phone number which should give you a decent prototype to get started on your custom function. In this example, make sure visitor_phone is enabled on the register page form.

Re: CP Guest + javascript code for phone number

My earlier instructions were incorrect on one part. Instead of putting "RegisterSubmit()" in the AJAX Submit field, put "RegisterSubmit" without parentheses.

Your JS code and mine both make use of the "username" field. By default, "username" is not added or enabled on a self-registration. For the code to work, make sure "username" is addded and enabled.

The code you have is indeed trying to take the "username" and place it into the "visitor_phone" but the code is doing additional logic to check if every single character of the username is in the Unicode range of numeric values:

if((charCode > 47) && (charCode < 58))

The username likely doesn't have numeric values so it skips every letter of the username and tries to write a blank value to the visitor_phone. To test this, enter a username with some numeric values like "abc123". Only "123" will get set to visitor_phone.

Chrome Developer Tools, Firebug, or similar tools are your friend when debugging JS code. Enable the console in each tool which will give you alerts about any particular errors. For example, you would get an error in the console that JS couldn't reference "username" if it wasn't added to the form (bullet point 2). You can also write your own debug messages in JS with console.log() lines, such as console.log("charCode is: " + charCode);. Just make sure to remove them after you are done troubleshooting for browser compatibilty.

Re: CP Guest + javascript code for phone number

‎07-22-201312:24 AM

Thanks rmehra, now I can copy the username (which is a phone number) to the visitor_phone field. Next step is to add a function that check the username (in fact a phone number) and add a prefix for the numbers begning by 079, 078, 077 or 076.

Re: CP Guest + javascript code for phone number

‎07-22-201304:50 AM

It's ok, I have found the javascript that I need for this function.

But now, I have another issue. I would like to use phone number in internation format like 004179309XX or 0336367XXXX but it's not working, CP Guest doesn't allowed my to send SMS to this kind of numbers. Anyone has the same problem ?

There are options under Administrator -> SMS Services -> SMS Gateways -> Mobile Number Settings that may help. Try playing around with these settings for your international settings and test functionality with a Send SMS tests.

Enable SMS Gateway debugging from Administrator -> SMS Services -> SMS Gateways -> Mobile Number Settings. Attempt to send a SMS message where it fails and then view Support -> Application Log. Possibly, it isn't CPG failing to send the international number and instead being rejected by your SMS gateway.

Try disabling validation on your self-registration form for visitor_phone and attempt registering another user.