Author Topic: no number validation for telephone input?  (Read 4572 times)

287d

  • Beginner
  • *
  • Posts: 45
no number validation for telephone input?
« on: August 19, 2009, 20:16:20 pm »
Hi Guys,

It seems the reg form for virtuemart allows alphanumeric characters for the telephone field. I have looked through some of the files and have no idea how to change this.

Does anyone have a quick way to do this so the telephone field only accepts number?

Thanks in advance.

MikeUK

  • Global Moderator
  • Full Member
  • *
  • Posts: 1344
Re: no numer validation for telephone input?
« Reply #1 on: August 19, 2009, 23:28:06 pm »
Are you familiar with VM admin and managing user fields? If not take a look at user and / or developer manuals (link in my signature).


Get answers faster:

I can build your online shop, setup or customize Virtuemart or help your existing shop maximize its potential. Email / PM for info

287d

  • Beginner
  • *
  • Posts: 45
Re: no numer validation for telephone input?
« Reply #2 on: August 20, 2009, 01:56:41 am »
Hi,

Thanks. I'd looked in the user manuals and just had a look at the developer manual too but can't find anything that gives me a clue.

I know that the user fields in the components don't work properly and following an old guide by a user on this forum was able to add teh Miss field into the reg form.

I though that after this it would be easily to find where the validation comes from to chaneg the telephone number from text (required) to number required. But - at least for me - not so.

IS this at all possible?

Thanks again

MikeUK

  • Global Moderator
  • Full Member
  • *
  • Posts: 1344
Re: no numer validation for telephone input?
« Reply #3 on: August 20, 2009, 10:06:49 am »
I know that the user fields in the components don't work properly and following an old guide by a user on this forum was able to add teh Miss field into the reg form.

Actually, I don't really understand this. Sounds more like VM 1.0x. The user fields component works fine. If there are any bugs they should be reported in the bug tracker.

What you want to do requires some code changes, and probably you would need to be familiar with php / html coding in this area. If you were able to give it a go, others might be able to look at what you've done and make suggestions.
Get answers faster:

I can build your online shop, setup or customize Virtuemart or help your existing shop maximize its potential. Email / PM for info

287d

  • Beginner
  • *
  • Posts: 45
Re: no numer validation for telephone input?
« Reply #4 on: August 21, 2009, 03:16:05 am »
Hi,

I'm using VM 1.1.3 / J 1.5.8.


Regarding the userfields issue see here: http://forum.virtuemart.net/index.php?topic=57751
Basically if I added Miss in the user management in VM it would not show in the form and added it as that poster suggested in the above post.


I though that there would be a similar file in which the validation field could be amended to check for just numbers (and would be happy to add my suggestions or tests here if I could find it to play with...).


I did look through the manuals but can't find where the JS is loaded from... :(

It's odd that I'm the only one that seems to have wondered this. Or perhaps in other countries people add dashes and so no-one has wondered...?!

Thanks.

MikeUK

  • Global Moderator
  • Full Member
  • *
  • Posts: 1344
Re: no number validation for telephone input?
« Reply #5 on: August 21, 2009, 10:27:28 am »
Ok, I see. Perhaps one approach would be  looking for the required fields and email validation part of the code. One of the files involved is ps_userfield.php (but there are others also), also ps_html was mentioned in the other thread.

I think the thing with the field is, that a lot of people write tel numbers like (11111) 1111111 or 1111 - 11111- 111.
Get answers faster:

I can build your online shop, setup or customize Virtuemart or help your existing shop maximize its potential. Email / PM for info

287d

  • Beginner
  • *
  • Posts: 45
Re: no number validation for telephone input?
« Reply #6 on: August 21, 2009, 19:37:25 pm »
Ok. Good tip. Here most people just put in numbers which is why people like number validation. I'm going to have a look tonight and will update on what I find.

287d

  • Beginner
  • *
  • Posts: 45
Re: no number validation for telephone input?
« Reply #7 on: August 27, 2009, 05:07:16 am »
Hello all,

With regards to adding number validation I think I am almost there but need some advise.

I think it's in 2 steps:
1. Add numeric as a value in the backend form, then
2. Add validation for it in the relevant file.

Please let me know your thoughts on what I have found below. Many Thanks.

-------------------------------------------------------------------



Firstly, so that the user form management has a "numeric" as a value in the form and so the relevant input is marked "numeric" for the script I assume this is all I have to do:


1. In   administrator/components/com_virtuemart/html/admin.user_field_form.php there is:
Code: [Select]
line 67 --> $types['text'] = $VM_LANG->_('VM_FIELDS_TEXTFIELD');
I assume I would add something like
Code: [Select]
$types['numeric'] = $VM_LANG->_('VM_FIELDS_NUMBERFIELD');
And...


2. In   administrator/components/com_virtuemart/languages/admin/english.php
there is:
Code: [Select]
line 304 'VM_FIELDS_TEXTFIELD' => 'Text Field',

So I should add a line like:
Code: [Select]
'VM_FIELDS_NUMBERFIELD' => 'Numeric Field',
to make it available from the backend.


Is this correct?




------


Secondly I have found where the javascript is and so just need to add valitdation there but how do I qualify the term numeric?



1. Location of javascript for validation:

>> administrator/components/com_virtuemart/classes/ps_userfield.php
This loads admin form and the javascript for the form - see line 641:

Code: [Select]
       echo '
            <script language="javascript" type="text/javascript">//<![CDATA[
            function '.$functioname.'() {
                var form = document.'.$formname.';
                var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", "i");
                var isvalid = true;
                var required_fields = new Array(\''. $field_list.'\');
             for (var i=0; i < required_fields.length; i++) {
                    formelement = eval( \'form.\' + required_fields[i] );



2. So I imagine if a I add an "if" statement here for "numeric" I am almost there, except that I think I am missing one more place to define "numeric" as for drop downs:

Code: [Select]
else if( formelement.options ) {
  if(formelement.selectedIndex.value == '') {                          
 document.getElementById(required_fields[i]+'_div').className += ' missing';
                                isvalid = false;


Thanks in advance for any suggestions!



287d

  • Beginner
  • *
  • Posts: 45
Re: no number validation for telephone input?
« Reply #8 on: September 02, 2009, 18:36:39 pm »
Anyone any ideas?

MikeUK

  • Global Moderator
  • Full Member
  • *
  • Posts: 1344
Re: no number validation for telephone input?
« Reply #9 on: September 02, 2009, 20:19:06 pm »
Did the code work in any way?

I'm not sure what $types['numeric'] refers to. It might be fine, but not sure where the 'numeric' is from.
Get answers faster:

I can build your online shop, setup or customize Virtuemart or help your existing shop maximize its potential. Email / PM for info