16
1 Chapter 3 Chapter 3 Self-server application Self-server application & & Server-side validation Server-side validation

Dynamic Web Pages Ch 3 V1.0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Dynamic Web Pages Ch 3 V1.0

1

Chapter 3Chapter 3Chapter 3Chapter 3Self-server applicationSelf-server application

&&Server-side validationServer-side validation

Page 2: Dynamic Web Pages Ch 3 V1.0

2

Self-server Applications• These applications are answering a

question that would usually be answered by the staff in the tours company.

• An example is how much does it cost to do this tour and another tour.

• We will create a tours calculator, (self-server application).

Page 3: Dynamic Web Pages Ch 3 V1.0

3

The tour calculator page - 1• Open the generic_template.php

and save as tourprice_processor.php and tourprice.php.

• The two pages are shown on the next slides.

Page 4: Dynamic Web Pages Ch 3 V1.0

4

The tour calculator page - 2

tourprice.php

Objects names:

txtNumberAdults

txtNumberChildren

cboTourName

Page 5: Dynamic Web Pages Ch 3 V1.0

5

The tour calculator page - 3

tourprice_processor.php

Calculate link to tourprice.php page

Contact link to contact.php

Page 6: Dynamic Web Pages Ch 3 V1.0

6

The tour calculator page - 4

Page 7: Dynamic Web Pages Ch 3 V1.0

7

The tour calculator page - 5• tourprice.php has the following

properties.– Form

• Name = frm_tourprice • Action = tourprice_processor.php• Method = POST

– Table inside the form• 4 rows • 2 columns • width of 60 percent

– List values• Highlights of Argentina, 500 • Highlights of Western Canada, 700 • Egyptian Pyramids and More, 900

Page 8: Dynamic Web Pages Ch 3 V1.0

8

Calculating the price - 1• Open tourprice_processor.php page.• Input the php code as shown to;

– declare and initialise the number of adults, kids and tour name.

– Calculate the price of the tour.

Check you have the same variable names in your tourprice.php page as those in quotes.

Variable declaration

Page 9: Dynamic Web Pages Ch 3 V1.0

9

Calculating the price - 2• Now you have calculated the tourprice

variable, you need to display it. This is done by placing php script amongst the html code, as shown below.

• Save and view the page. What happens when you don’t put in an amount for the adults or kids?

Page 10: Dynamic Web Pages Ch 3 V1.0

10

The calculator so far….• So far the calculator works if

numeric values are put in the adults and kids fields.

• Errors appear if not values are placed in the adults and kids fields.

• The next couple of slides are going to add a css rule for errors and trap the error with php code.

Page 11: Dynamic Web Pages Ch 3 V1.0

11

Adding new style to the css

• Add an error style to the css file with the following properties;– Type: class – Name: error– Weight : bold– Colour : #990000

• This style will be used if the client makes an error with the information for the tour calculator.

Page 12: Dynamic Web Pages Ch 3 V1.0

12

Server-side validation -1• Server-side validation is validating the

tourprice.php page variables sent to the tourprice_processor.php page.

• This is done by checking the two form variables for numerical values, as shown.

• If one of them doesn’t hold a numeric value the client is sent back to the tourprice.php page, displaying an error.

• Add the code.

Page 13: Dynamic Web Pages Ch 3 V1.0

13

Server-side validation- 2• Once the client is sent back to the

tourprice.php page the code to pick up this error is needed.

• This code shows the response to that variable and displays a message to the client.

Page 14: Dynamic Web Pages Ch 3 V1.0

14

Lab 3 - 1• In this lab you are to add a list/menu to

reservations.php and change the form action to call the page reservations_action.php.

• The two pages are shown on the next slides.• To have “Yes” or “No” displayed on

equipment you will have to write an if statement finding out if the box was ticked, “true” or not ticked, “false”.

if (equipment==“true” )

echo “No”;

else

echo “Yes”;

Page 15: Dynamic Web Pages Ch 3 V1.0

15

Lab 3 - 2

reservations.php

The value for each label is: 1 for Nepal Track, 2 for Alasken Wilderness, etc.

Page 16: Dynamic Web Pages Ch 3 V1.0

16

Lab 3 - 3

reservations_action.php. This page was created from tourtemplate.php.

Reservation Information from reservation.php page