dynamic web pages ch 3 v1.0

Post on 18-Jan-2015

590 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

1

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

&&Server-side validationServer-side validation

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

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.

4

The tour calculator page - 2

tourprice.php

Objects names:

txtNumberAdults

txtNumberChildren

cboTourName

5

The tour calculator page - 3

tourprice_processor.php

Calculate link to tourprice.php page

Contact link to contact.php

6

The tour calculator page - 4

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

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

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?

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.

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.

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.

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.

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”;

15

Lab 3 - 2

reservations.php

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

16

Lab 3 - 3

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

Reservation Information from reservation.php page

top related