ECommerce Infrastructure - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

ECommerce Infrastructure

Description:

We're going to create a form together. Then we'll add the VBScript to validate the input ... rv = false. elseif not (Document.UserInput.CellPhoneNumber.Value ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 24
Provided by: cimsCl
Category:

less

Transcript and Presenter's Notes

Title: ECommerce Infrastructure


1
E-CommerceInfrastructure Security
  • Lecture 8
  • Advanced VB Script

2
Answering Your Question
  • ltform namefmrOuttergt
  • ltINPUT TYPE"TEXT" NAME"OutterText" SIZE"20"
    MAXLENGTH"8"gtltbrgt
  • lthrgt
  • ltFORM NAMEfrmInnergt
  • ltINPUT TYPE"TEXT" NAME"InnerText"
    SIZE"20" MAXLENGTH"8"gtltbrgt
  • ltINPUT TYPE"reset"gt
  • lt/formgt
  • lthrgt
  • ltINPUT TYPE"TEXT" NAME"OutterText2"
    SIZE"20" MAXLENGTH"8"gtltbrgt
  • ltINPUT TYPE"reset"gt
  • lt/formgt

3
Multiple Forms
  • You cant embed forms inside each other
  • You can have more than one form on an html page

4
Agenda
  • VB Script - Validating Users Input

5
Validating Users Input
  • So weve got a form
  • The user types in a bunch of information
  • Then the user clicks SUBMIT
  • This data will be transferred to the server
  • Why not just test it on the server?

6
Motivation
  • Why require the trip across the network?
  • Latency
  • Server load
  • Keep it on the client
  • Increases speed
  • This is what client-side scripting is for

7
Two-Part Process
  • Certainly we dont want garbage coming to us
  • Lets check the format of the input and then give
    a warning if its not correct
  • Wed also like to shift focus to the incorrect
    element

8
What If There Is More than One Error?
  • Certainly there could be more than one error
  • Some different policies
  • Handle the first and stop
  • Show a message indicating all errors

9
The Better Approach
  • Showing everything might seem appropriate - more
    information
  • But users can get overwhelmed quite easily
  • So were going to handle the errors one at a time

10
Creating the Form
  • Open FrontPage, Dream Weaver, etc.
  • Were going to create a form together
  • Then well add the VBScript to validate the input

11
What the Form Must Contain
  • First Name
  • Last Name
  • Telephone number
  • Cell Phone Number
  • Birthday
  • Notes

12
The Final Product
13
Now Lets Create the VBScript
  • Well need a few different functions
  • Validate that inputs arent empty
  • All but the cell phone notes will be required
  • Validate that phone number birthday are entered
    correctly
  • Use a message box to show error

14
Make Sure the Entry is Present
  • Function IsEmpty(toCheck)
  • if toCheck.Value then
  • MsgBox Please fill in a value for _
    toCheck.text, vbCritical, _
  • Missing Info toCheck.name
  • IsEmpty true
  • else
  • IsEmpty false
  • end if
  • End function

15
Validating a Phone Number
  • Function ValidPhone(toCheck)
  • assumes that toCheck isnt empty (check before)
  • Dim regularExpression
  • Set regularExpression new RegExp
  • regularExpression.pattern \d3-\d3-\d4
  • if (not regularExpression.Test(toCheck.Value))
    then
  • MsgBox Please use the -- format
    for _ toCheck.text, vbCritical, _
  • Invalid phone number entered
    toCheck.name
  • ValidPhone false
  • else
  • ValidPhone true
  • end if
  • End function

16
Regular Expressions
  • - beginning of string
  • h will match hello but not ohio
  • - end of string
  • b will match crib but not bed
  • n matches repeats of preceding
  • a2 matches aa, baah, but not eat
  • \d matches any digit
  • \d will match 1, 2, 3, etc.

17
Regular Expressions (cont)
  • \d3-\d3-\d4
  • Matches 3 digits followed by - and three more
    digits followed by - and four digits
  • Does not allow other characters before or after

18
Validating a Birthday
  • Function ValidBDay(toCheck)
  • assumes that toCheck isnt empty (check before)
  • Dim regularExpression
  • Set regularExpression new RegExp
  • regularExpression.pattern \d2/\d2/\d4
  • if (not regularExpression.Test(toCheck.Value))
    then
  • MsgBox Please use the MM/DD/YYYY format for
    _ toCheck.text, vbCritical, _
  • Invalid birthday entered toCheck.name
  • ValidBDay false
  • else
  • ValidBDay true
  • end if
  • End function

19
Putting It All Together
  • function ValidateInformation
  • dim rv
  • rv True
  • if IsEmpty(Document.UserInput.FirstName) then
  • rv false
  • elseif IsEmpty(Document.UserInput.LastName)
    then
  • rv false
  • elseif IsEmpty(Document.UserInput.TelephoneNumbe
    r) then
  • rv false
  • elseif not ValidPhone(Document.UserInput.Telepho
    neNumber) then
  • rv false
  • elseif not (Document.UserInput.CellPhoneNumber.V
    alue "") then
  • if not ValidPhone(Document.UserInput.CellPhone
    Number) then
  • rv false
  • end if
  • elseif IsEmpty(Document.UserInput.Birthday)
    then
  • rv false
  • elseif not ValidBDay(Document.UserInput.Birthday
    ) then

20
Not Done Yet!
  • This works well, but
  • When the user makes a mistake, wed like to put
    focus on the thing that needs to be changed
  • Can we focus the form element?

21
Changing Focus
  • The focus method shifts the browsers attention
    to the object
  • i.e. ltform elementgt.Focus
  • ex. Document.UserInput.FirstName.Focus

22
Where To Apply This
  • Any time in this course in which you are asking
    the user for specific information with
    constraints
  • Of course, we can do better than this
  • ActiveX (date pickers, etc.)
  • OnChange event for Text or TextArea

23
Project 3 Is Due Tuesday _at_ 6pmFind a Group for
Project 4
FIN
Write a Comment
User Comments (0)
About PowerShow.com