View Full Version : Phone Number Checking
blakerockstar
04-27-06, 08:04 PM
Is their a way I could make a item that would check to make sure 10 digits were entered in the phone number field. Similar to the way that the zip code field checks for at least 5 digits.
How would I go about doing this?
DesignExtend-MSI
04-27-06, 08:36 PM
Yes. If you've got a copy of the standalone scripts that came with Mia a while back you can see the info in there.
Bruce - PhosphorMedia
04-27-06, 09:20 PM
something like
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, '+', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, '/', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, '(', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, ')', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, '-', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, 'x', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, '.', '' ) }">
<MvASSIGN NAME = "l.phone" VALUE = "{ glosub( l.phone, ' ', '' ) }">
<MvIF EXPR = "{ NOT isdigit( l.phone ) }">
<MvASSIGN NAME = "l.valid" VALUE = 0>
</MvIF>
<MvIF EXPR = "{ len( l.phone ) NE 10 }">
<MvASSIGN NAME = "l.valid" VALUE = 0>
</MvIF>
<MvELSE>
<MvASSIGN NAME = "l.valid" VALUE = "1">
</MvIF>
but not sure what you mean by "make it an item"
blakerockstar
04-27-06, 11:47 PM
What I mean by and Item is adding a new item with the code that would do the checking and assigning that to the ACAD screen.
My thinking was similar, then I would just compile the script and add it as an item.
But would something like this work directly inside the customer fields tab template:
<mvt:item name="fonts" param="body_font">
<mvt:if expr="NOT g.Customer_ShipPhone_Invalid">
<b>Phone Number:</b>
<mvt:else>
<mvt:if expr="{len(g.Customer_ShipPhone NE 10)}">
<font color="red">
<b>Phone Number:</b>
</font>
</mvt:if>
</mvt:if>
</mvt:item>
</td><td align="left" valign="middle">
<mvt:item name="fonts" param="body_font">
<input type="text" name="Customer_ShipPhone" size=25 value="&mvte:global:Customer_ShipPhone;">
</mvt:item>
Bruce - PhosphorMedia
04-28-06, 12:29 AM
no because the test has to occur on submit....and otherwise, when first reaching the screen the test would be invalid so the Phone Number would appear in red.
You would need to do quite a bit of hacking to get the phone number to test to 10 digits.
...and for what...most folks would just put 1231231233...phone numbers should never be require IMO for online sales...I (and just about every online user I know) would not enter their real phone number)...but that is just MO
blakerockstar
04-28-06, 12:40 AM
I'm not trying to require the phone number, just check that if they have input a number that it is 10 digits.
The zip code field checks for at least 5 digits by miva default correct?
If I were to take your code and compile it and install it as an Item would it work?
This is for a clients site, and I actually have the same opinion but, trying to please the client as well.
Bruce - PhosphorMedia
04-28-06, 12:44 AM
It would be easier to convince the client otherwise...no, it would not work...you would have to intercept the post from the initiall account page, do your checks...and do all of the other checks as well, then display the result on a custom page...at least as far as I know...
blakerockstar
04-29-06, 12:16 AM
Is it possible to even get the miva 5 source files (.mv) so that I could try and implement this function? I've already downloaded the Miva5 source, but they are all .mvc.
Where do I begin to attempt to retrieve the posted info and check it.:confused:
Bruce - PhosphorMedia
04-29-06, 07:13 PM
If you want, one of our developers whipped up a system module that does this (show off)...we could probably let you use it...although we couldn't support it for free.
Mark Hughes
05-02-06, 06:36 PM
Hello Blakerockstar,
Is it possible to even get the miva 5 source files (.mv) so that I could try and implement this function? I've already downloaded the Miva5 source, but they are all .mvc.
MIVA makes available a selection of the source from the MIVA Merchant 5 application. http://smallbusiness.miva.com/products/mmlsk/ Such API documentation as is already available is here: http://smallbusiness.miva.com/support/docs/api/. (Everyone agrees that there needs to be more.) I encourage you to continue asking questions here, because a lot of knowledgeable folk enjoy answering.
Where do I begin to attempt to retrieve the posted info and check it.:confused:
To intercept the phone number submission, a system module will be more suitable than an item. It sounds as if Bruce already has a solution for you, but for your and other's benefit, here is how I would go about creating the module you need.
I think of needing to write code to accomplish 4 main tasks:
1) Intercept the Action
A system module will allow you to insert instructions for MIVA Merchant to execute upon receiving the form post containing the information you are interested in. MIVA Merchant will consult the SystemModule_Action function from each assigned system module whenever it, Merchant, detects a value for Action in the request or form post.
View source on or consult the template for the form you are interested in and check the hidden input field named ?Action?. You can then surround your phone validation instructions with a conditional based on this value. E.g.
<MvFUNCTION NAME = "SystemModule_Action" PARAMETERS = "module var, action" STANDARDOUTPUTLEVEL = "">
<MvIf expr=?{l.action EQ ?XXYY?}?>
[Code to validate phone number]
</MvIf>
<MvFUNCRETURN VALUE = "{1}">
</MvFUNCTION>
2) Set the screen/destination
You will notice another hidden input in the form, one called ?Screen?. This is the variable that signals Merchant which screen to build in response to the form post. If Screen = PROD, Merchant will execute the instructions to build the ?Product? screen. If Screen = OSEL, Merchant will execute the instructions to build the ?Checkout: Shipping/Payment Selection? screen.
You will probably want to signal Merchant to display a different screen next instead. In cases of invalid entries, you normally want Merchant to display the same screen over again. So if you are validating a submission made from the ?Checkout: Customer Information? (OCST) screen, you will want Merchant to return to that screen:
<MvAssign name=?g.Screen? value=?OCST?>
3) Write a message for display
You can use the Messages item to display text explaining to the user why they are back at the same page again/
<MvAssign name=?l.ok? value=?{
[g.Module_Library_Utilities].Message_Error(?Please check the phone number you entered.?)
}>
4) Set the invalidity flag.
You can also set the invalidity flag, so that Merchant renders the prompt beside the phone number in red, to highlight it.
<MvAssign name=?g.ShipPhone_Invalid? value=?{1}?>
So you will end up with something like:
<MvFUNCTION NAME = "SystemModule_Action" PARAMETERS = "module var, action" STANDARDOUTPUTLEVEL = "">
<MvIf expr=?{l.action EQ ?XXYY?}?>
[Code to validate phone number]
<MvIf expr=?{NOT l.valid}?>
<MvAssign name=?l.ok? value=?{
[g.Module_Library_Utilities].Message_Error(?Please check the phone number you entered.?)
}>
<MvAssign name=?g.ShipPhone_Invalid? value=?{1}?>
<MvAssign name=?g.Screen? value=?OCST?>
</MvIf>
</MvIf>
<MvFUNCRETURN VALUE = "{1}">
</MvFUNCTION>
A final point, you may want to have SystemModule_Action return 0 when l.action = ?XXYY? A return of zero will signal MIVA Merchant to skip the instructions it would normally follow in response to Action = ?XXYY? and move on to the instructions about building the screen.
HTH,
Mark
Brandon MUS
05-05-06, 10:22 PM
What about Javascript as a solution? It would be very easy to make sure that the user input only numbers and that strlen is >= 10. Of course this isn't the best solution because disabling javascript will get you around it, but its not a bad one either.
To make this work, you want to edit the <form> and add an onsubmit="javascript:validate();" (or something similiar).
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.