Security

last person joined: yesterday 

Forum to discuss Enterprise security using HPE Aruba Networking NAC solutions (ClearPass), Introspect, VIA, 360 Security Exchange, Extensions, and Policy Enforcement Firewall (PEF).
Expand all | Collapse all

CP Guest + javascript code for phone number

This thread has been viewed 10 times
  • 1.  CP Guest + javascript code for phone number

    Posted Jul 18, 2013 10:43 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.


    Thanks

     

    Regards

     

    Dimitri



  • 2.  RE: CP Guest + javascript code for phone number
    Best Answer

    Posted Jul 18, 2013 08: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.

     

    <script type="text/JavaScript"><!--{literal}
    function RegisterSubmit(form_name) {
        var frm = document.forms[form_name];
        var error = '';
        // Checking here...
    
        if (error != '') {
            alert(error);
            Nwa_EnableFormButtons(form_name);
            return false;
        }
    
        // Reverse the phone number and put it as the username.
        if (frm.visitor_phone.value != '') {
            var name = '';
            var phone = frm.visitor_phone.value.split('');
            for (var i = 0; i < phone.length; i++) {
                var charCode = phone[i].charCodeAt(0);
                if((charCode > 47) && (charCode <  58)) {
                    name = phone[i] + name;
                }
            }
            frm.username.value = name;
        }
    
        return true; // Proceed to regular
    }
    //-->
    {/literal}</script>


  • 3.  RE: CP Guest + javascript code for phone number

    Posted Jul 19, 2013 02:23 AM

    Thanks.

     

    I have tried your solution and changed it to copy the username to the phone number but it's not working. Value isn't passed from the field to the other. Any idea why ?

     

    Here is my code 

      

    <script type="text/JavaScript"><!--{literal}
    function RegisterSubmit(form_name) {
        var frm = document.forms[form_name];
        var error = '';
        // Checking here...
    
        if (error != '') {
            alert(error);
            Nwa_EnableFormButtons(form_name);
            return false;
        }
    
        // Reverse the username  and put it as the visitor_phone.
        if (frm.username.value != '') {
            var phone = '';
            var user_name = frm.username.value.split('');
            for (var i = 0; i < user_name.length; i++) {
                var charCode = user_name[i].charCodeAt(0);
                if((charCode > 47) && (charCode <  58)) {
                    phone = user_name[i] + phone;
                }
            }
            frm.visitor_phone.value = phone;
        }
    
        return true; // Proceed to regular
    }
    //-->
    {/literal}</script>

      

    Dimitri



  • 4.  RE: CP Guest + javascript code for phone number

    Posted Jul 19, 2013 01:15 PM

    A few suggestions and ideas:

     

    • 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.


  • 5.  RE: CP Guest + javascript code for phone number

    Posted Jul 22, 2013 03: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.

     

    Any idea how to start this function ? I am a bit lost with Javascript

     

    Thanks again


    Dimitri



  • 6.  RE: CP Guest + javascript code for phone number

    Posted Jul 22, 2013 07:51 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 ?

     

    Thanks

     

    Dimitri



  • 7.  RE: CP Guest + javascript code for phone number

    Posted Jul 22, 2013 01:53 PM

    Nice work on the JavaScript function.  Can you expand on what you mean by CP Guest not allowing you to send SMS messages in international format?

     

    • Can you test manually sending an SMS message from Administrator -> SMS Services -> Send SMS?
    • 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.


  • 8.  RE: CP Guest + javascript code for phone number

    Posted Jul 23, 2013 03:03 AM

    Thanks for your help on the script :)

     

    • So what I mean is if I want to send a SMS to an international number like 004179309XXXX or 00336378XXXX, I can't. Thru the SMS Services it says that it isn't a valid phone number. 
    • I don't know how to fill in the settings to use international phone numbers (my SMS provider is SMS Global).
    • I got an error message "ERROR: 102 SMSGlobalMsgID" so it seems that SMS Global doesn't like the format of the number because it is working with +41 or +33 (but I don't want this format).


  • 9.  RE: CP Guest + javascript code for phone number

    Posted Jul 23, 2013 07:15 AM

    Problem solved for the international phone numbers. Just need to add 00 in National Prefix and then it works fine for numbers begining by 0041 or 0033 or 00XX.



  • 10.  RE: CP Guest + javascript code for phone number

    Posted Jul 23, 2013 12:55 PM

    Great work!