1 forms. 2 our goal is to design a form like that shown below

87
1 Forms

Upload: horace-wilcox

Post on 02-Jan-2016

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Forms. 2 Our goal is to design a form like that shown below

1

Forms

Page 2: 1 Forms. 2 Our goal is to design a form like that shown below

2

Our goal is to design a form like that shown below

Page 3: 1 Forms. 2 Our goal is to design a form like that shown below

3

And to process the information submitted to

make a receipt like the one below.

Page 4: 1 Forms. 2 Our goal is to design a form like that shown below

4

Choose some page properties (e.g. a font

family, size, etc.)

Page 5: 1 Forms. 2 Our goal is to design a form like that shown below

5

Go to Insert/HTML/Text Objects/H1

Page 6: 1 Forms. 2 Our goal is to design a form like that shown below

6

Enter some text in the resulting <h1>

header tags and center it.

Page 7: 1 Forms. 2 Our goal is to design a form like that shown below

7

Forms

• The purpose of this page is to collect information from someone.

• The interactive parts of a web page are placed in a form. The implication is that something will be done with this data – that there will be some action, that it will be handled.

Page 8: 1 Forms. 2 Our goal is to design a form like that shown below

8

The Form Handler

• This project will consist of two files. • The first has the form and is for the viewer to

enter information. • The second handles the information collected on

the form. • When we insert a form onto the first page, it will

ask about its action. We will start a second file, so that we answer this question when it arises.

Page 9: 1 Forms. 2 Our goal is to design a form like that shown below

9

Make a new file, it should be a dynamic, php file.

Page 10: 1 Forms. 2 Our goal is to design a form like that shown below

10

Save the second file.

Page 11: 1 Forms. 2 Our goal is to design a form like that shown below

11

Return to the first file and place the

cursor in the body after the <h1> tags.

Page 12: 1 Forms. 2 Our goal is to design a form like that shown below

12

Go to Insert/Form/Form

Page 13: 1 Forms. 2 Our goal is to design a form like that shown below

13

Use the Browse button to location the second file which will handle the first file’s action.

Page 14: 1 Forms. 2 Our goal is to design a form like that shown below

14

Choose a method (Post for now), give the form a name and click OK.

Page 15: 1 Forms. 2 Our goal is to design a form like that shown below

15

Form HTML

• The resulting HTML is: <form action="Evaluation_Handler.php"

method="post" name="frmEvaluation"> </form>

• All of the items on a page that a user might interact with belong between the <form> tags. – Note the action path should be relative in this

case.

Page 16: 1 Forms. 2 Our goal is to design a form like that shown below

16

Let us use a table with 3 rows and 1 column to organize our form.

Use the Insert Table button and the resulting dialog box.

Page 17: 1 Forms. 2 Our goal is to design a form like that shown below

17

In the first row, insert another table with 3

rows and 4 columns.

Page 18: 1 Forms. 2 Our goal is to design a form like that shown below

18

Enter text in the first cell and with the cursor in the second go to Insert/Form/Textfield

Page 19: 1 Forms. 2 Our goal is to design a form like that shown below

19

Form with Textfield inserted.

Page 20: 1 Forms. 2 Our goal is to design a form like that shown below

20

Go to Code View and give the textbox a

name that is meaningful in the context.

The default name was textfield. Giving it a meaningful name is known as self-documenting code and goes a long way to preventing confusion later on.

You can get rid of the panel group by clicking on the arrow between the panel group and document window.

Page 21: 1 Forms. 2 Our goal is to design a form like that shown below

21

Enter more text and textfields as shown.

Page 22: 1 Forms. 2 Our goal is to design a form like that shown below

22

Merge the first two columns of the third

row.

Page 23: 1 Forms. 2 Our goal is to design a form like that shown below

23

Go to Insert/Form/Radio Group

Page 24: 1 Forms. 2 Our goal is to design a form like that shown below

24

Enter a name for the Radio Group, put in the labels (what a viewer

will see) and values (what a coder will use) for the choices.

Radio buttons are used for situations in which the user can choose one and only one of the options.

Page 25: 1 Forms. 2 Our goal is to design a form like that shown below

25

Eliminate the break tags <br> if you want the radio buttons on the same line.

Page 26: 1 Forms. 2 Our goal is to design a form like that shown below

26

Go to Insert/Form/List/Menu

Page 27: 1 Forms. 2 Our goal is to design a form like that shown below

27

Give the <select> tag a self-documenting name, expand the Properties Inspector, click on the List Values button.

Page 28: 1 Forms. 2 Our goal is to design a form like that shown below

28

Add labels (what will be seen) in the drop-down list menu and

their corresponding values. Click on the + button to add more.

Page 29: 1 Forms. 2 Our goal is to design a form like that shown below

29

Result of adding the menu (drop-down list)

Page 30: 1 Forms. 2 Our goal is to design a form like that shown below

30

In the second row of the outer table,

insert a table of 5 rows and 2 columns.

Page 31: 1 Forms. 2 Our goal is to design a form like that shown below

31

Merge the columns the first row and

repeat for the second row.

Page 32: 1 Forms. 2 Our goal is to design a form like that shown below

32

Place the cursor in the second of the merged rows. Go to Modify/Table/Split Cell. Choose to split it into 5 columns.

Page 33: 1 Forms. 2 Our goal is to design a form like that shown below

33

Enter the rating scale explanations in the

five cells. Note that in design, if one hits the Enter keys, one gets paragraph tags <p>, which usually end up giving one a double spaced effect between paragraphs.

To achieve a single spacing effect we want break tags <br> which can be achieved in design by hitting Shift-Enter.

Page 34: 1 Forms. 2 Our goal is to design a form like that shown below

34

Enter the text of the first evaluation question and in the

adjacent column insert a RadioGroup with 5 RadioButtons.

Page 35: 1 Forms. 2 Our goal is to design a form like that shown below

35

Naming Issue

• We should give the RadioGroup a self-documenting name, but how descriptive should we be? – We might be very descriptive and call it

radQuestionClearObjective. If there are only a few questions, this is a good approach.

– If there are going to be several questions that we will want to treat almost identically, then a consistent naming scheme will aid in this process. In such a case we might go for radQ1, radQ2, etc.

Page 36: 1 Forms. 2 Our goal is to design a form like that shown below

36

After eliminating the break <br> tags, it should look like the following.

Note that when we made the second row have 5 columns, Dreamweaver decided that in the third row which has two columns, the first cell would have a colspan 4. But we can change that.

Page 37: 1 Forms. 2 Our goal is to design a form like that shown below

37

Change the colspans to 3 and 2 and then center the radio buttons.

Page 38: 1 Forms. 2 Our goal is to design a form like that shown below

38

Use copy and paste in code view to finish the other rows. Don’t forget to change the radiogroup name for each question.

Page 39: 1 Forms. 2 Our goal is to design a form like that shown below

39

If you’re like me and can’t spell, use the spell checker. Go to Text/Check Spelling.

Page 40: 1 Forms. 2 Our goal is to design a form like that shown below

40

In the last row of the outer table, enter some text a

break tag <br> and then insert a TextArea.

Page 41: 1 Forms. 2 Our goal is to design a form like that shown below

41

Use the Character Width (cols) and Number of Lines (rows) attributes to control the size of the TextArea.

Give it a meaningful name!

Page 42: 1 Forms. 2 Our goal is to design a form like that shown below

42

Upload it to the server and look at it in a browser.

Let us

1. Put some space between the three sections using break tags <br>.

2. Reduce the width of the TextArea and increase its

height.

Page 43: 1 Forms. 2 Our goal is to design a form like that shown below

43

Result of changing textarea. Note that the before viewing it in the browser, the textarea looked to be a good size when seen in Dreamweaver Design View.

Always view in a browser (maybe even different browsers) before accepting a design.

Page 44: 1 Forms. 2 Our goal is to design a form like that shown below

44

One can use a horizontal rule (Insert/HTML/Horizontal Rule)

to make section separations more distinct.

Page 45: 1 Forms. 2 Our goal is to design a form like that shown below

45

After the outer table but still with in the form place a button

that the user can click to submit his or her evaluation. Buttons can be made to do many things now, but oif the button’s only job is to submit a form, choose Submit as the Type.

Page 46: 1 Forms. 2 Our goal is to design a form like that shown below

46

Edit the value attribute and place the button in

a paragraph with center alignment.

Page 47: 1 Forms. 2 Our goal is to design a form like that shown below

47

The Handler

• Eventually we want to collect and perhaps even analyze the data submitted, but for now we will make a “receipt” – a slightly processed spitting back of the information submitted.

Page 48: 1 Forms. 2 Our goal is to design a form like that shown below

48

Choose some page properties (e.g. a font family, size, etc.). Place some text in <h1> tags, center it.

Page 49: 1 Forms. 2 Our goal is to design a form like that shown below

49

Let’s place the date in a table with three rows, one column.

Page 50: 1 Forms. 2 Our goal is to design a form like that shown below

50

Insert php tags in the first row and start with the code to print the date.

Page 51: 1 Forms. 2 Our goal is to design a form like that shown below

51

print date('F j, Y')."<br />";

• The code above demonstrates how php handles concatenation (the placing of one thing after another – in this case the date and then a break tag). PHP uses a dot to indicate that two things should be concatenated.

• The code above also shows a newer style for the break tag. In the newer style unpaired tags end in slash angle bracket. – <br> becomes <br />

Page 52: 1 Forms. 2 Our goal is to design a form like that shown below

52

About compliance

Because we did mot specify otherwise, Dreamweaver elected to go with the looser style.

Page 53: 1 Forms. 2 Our goal is to design a form like that shown below

53

To make a newer file XHTML compliant, go to File/Convert/XHMTL

Page 54: 1 Forms. 2 Our goal is to design a form like that shown below

54

To make new document XHTML compliant, go to Edit/Preferences choose New Document and check

Make Document XHTML Compliant

Page 55: 1 Forms. 2 Our goal is to design a form like that shown below

55

Retrieve course data from the evaluation page

and place it on the evaluation summary page.

Page 56: 1 Forms. 2 Our goal is to design a form like that shown below

56

$course = "{$_POST['txtCourse']}";

• There is an array of information that is brought over when the Evaluation form was posted. It is contained in the $_POST array. – An array is a set of associated variables or objects.

• One specifies an element of the array (a specific member of the set) by using an index in the square brackets.– Sometimes the index is a number and sometimes it is a

name.

Page 57: 1 Forms. 2 Our goal is to design a form like that shown below

57

Result so far

Page 58: 1 Forms. 2 Our goal is to design a form like that shown below

58

More of the same

Notice how the use of self-documenting variable names makes the code more readable.

Page 59: 1 Forms. 2 Our goal is to design a form like that shown below

59

Page 60: 1 Forms. 2 Our goal is to design a form like that shown below

60

Page 61: 1 Forms. 2 Our goal is to design a form like that shown below

61

Page 62: 1 Forms. 2 Our goal is to design a form like that shown below

62

Our choice of values

• We got a yes or no answer on the “required” radio buttons because that is the set of values we chose for the individual radio buttons.

• Similarly we got a number for the drop-down list grade because those are the values we chose.

• These values were chosen more with storage in mind (and possibly calculation) than with display in mind.

Page 63: 1 Forms. 2 Our goal is to design a form like that shown below

63

The IF structure

The if structure allows one to test for a certain condition and then respond differently depending on whether the condition is found to hold (be true) or not.

Page 64: 1 Forms. 2 Our goal is to design a form like that shown below

64

if($required == "Yes")

• The above code is the start of the if structure. It starts with the keyword if.

• It is followed by a condition/proposition/ Boolean expression in parentheses. This part asks a true-or-false question. In this case, it asks “Is it true or false that the required variable is equal to “Yes”?”

Page 65: 1 Forms. 2 Our goal is to design a form like that shown below

65

Are you asking me or are you telling me?

• Note the condition uses two equal signs. • An easy mistake to make to have one equal sign

instead of two. – One equal sign is not a syntax error (a mistake in the

code rules that means the code can’t be executed) rather it is a logical error (a mistake in the code that will run but give incorrect/undesired results).

– Remember one equal sign means you’re telling two things to be equal (a.k.a. an assignment statement) whereas two equal signs means you’re asking if two things are equal.

Page 66: 1 Forms. 2 Our goal is to design a form like that shown below

66

if($required == "Yes"){

print "required";}

• After the condition comes a a set or curly brackets. Inside the brackets are all of the statements (a block of statements) that one wants executed when the condition is true. – Note that there is no semicolon after the condition.– If there is only one statement, you don’t need the curly

brackets. • (I usually include the curly brackets even when there’s only

one statement. This approach anticipates that I or someone else may edit the code and add statements.)

Page 67: 1 Forms. 2 Our goal is to design a form like that shown below

67

if($required == "Yes"){print "required";}else {print "elective";}

• One has the option of following the “true block” with the keyword else and a second block that will be executed when the condition is found to be false.

Page 68: 1 Forms. 2 Our goal is to design a form like that shown below

68

Using a switch to deal with a bunch of “cases”

Page 69: 1 Forms. 2 Our goal is to design a form like that shown below

69

Page 70: 1 Forms. 2 Our goal is to design a form like that shown below

70

Dealing with the questions one at a time.

Page 71: 1 Forms. 2 Our goal is to design a form like that shown below

71

Page 72: 1 Forms. 2 Our goal is to design a form like that shown below

72

Calculating a average rating.

Page 73: 1 Forms. 2 Our goal is to design a form like that shown below

73

Page 74: 1 Forms. 2 Our goal is to design a form like that shown below

74

Dealing with the questions as a set.

Page 75: 1 Forms. 2 Our goal is to design a form like that shown below

75

Make a variable for the comments, etc.

Page 76: 1 Forms. 2 Our goal is to design a form like that shown below

76

Result with comment section

Page 77: 1 Forms. 2 Our goal is to design a form like that shown below

77

An issue with quotes will need to be resolved.

Page 78: 1 Forms. 2 Our goal is to design a form like that shown below

78

An issue with quotes. See what I mean?

We need to learn some string processing to deal with this problem.

Page 79: 1 Forms. 2 Our goal is to design a form like that shown below

79

And should we allow the user to write HTML?

Page 80: 1 Forms. 2 Our goal is to design a form like that shown below

80

Result of the user writing HTML

Page 81: 1 Forms. 2 Our goal is to design a form like that shown below

81

Enter Your Name (Post)

Page 82: 1 Forms. 2 Our goal is to design a form like that shown below

82

Your Name Handler (Post)

Page 83: 1 Forms. 2 Our goal is to design a form like that shown below

83

Result of post version

Page 84: 1 Forms. 2 Our goal is to design a form like that shown below

84

Enter Your Name (Get)

Page 85: 1 Forms. 2 Our goal is to design a form like that shown below

85

Your Name Handler (Get)

GET instead of POST

Page 86: 1 Forms. 2 Our goal is to design a form like that shown below

86

Result of get version

Page 87: 1 Forms. 2 Our goal is to design a form like that shown below

87

GET versus POST

GET POSTLess Private/Secure More Private/Secure

Can’t use with larger amounts of data

Can use with larger amounts of data

Handler is “bookmarkable” Handler is NOT “bookmarkable”

User can get new results without returning to initial page

User can’t get new results without returning to initial page