Sie sind auf Seite 1von 8

Assignment:

1. Differentiate $_GET from $_POST variable.


2. Define form ID, method and action.
3. Define CSS Colors and NTH.

Answers:

1.
a. $_GET Variable

The GET Method


In GET method the data is sent as URL parameters that are usually
strings of name and value pairs separated by ampersands (&). In general,
a URL with GET data will look like this:
http://www.example.com/action.php?name=john&age=24
The bold parts in the URL are the GET parameters and the italic parts are
the value of those parameters. More than one parameter=value can be
embedded in the URL by concatenating with ampersands (&). One can
only send simple text data via GET method.

Advantages and Disadvantages of Using the GET Method


Since the data sent by the GET method are displayed in the URL, it is
possible to bookmark the page with specific query string values.
The GET method is not suitable for passing sensitive information such
as the username and password, because these are fully visible in the
URL query string as well as potentially stored in the client browser's
memory as a visited page.
Because the GET method assigns data to a server environment
variable, the length of the URL is limited. So, there is a limitation for the
total data to be sent.
PHP provides the superglobal variable $_GET to access all the
information sent either through the URL or submitted through an HTML
form using the method="get"

<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of PHP GET method</title>
</head>
<body>
<?php
if(isset($_GET["name"])){
echo "<p>Hi, " . $_GET["name"] . "</p>";
}
?>
<form method="get" action="<?php echo $_SERVER["PHP_SELF"];?>">
<label for="inputName">Name:</label>
<input type="text" name="name" id="inputName">
<input type="submit" value="Submit">
</form>
</body>

b. $_POST Variable
An associative array of variables passed to the current script via the HTTP
POST method when using application/x-www-form-urlencoded or
multipart/form-data as the HTTP Content-Type in the request.

The POST Method


In POST method the data is sent to the server as a package in a separate
communication with the processing script. Data sent through POST
method will not visible in the URL.

Advantages and Disadvantages of Using the POST Method


It is more secure than GET because user-entered information is never
visible in the URL query string or in the server logs.
There is a much larger limit on the amount of data that can be passed
and one can send text data as well as binary data (uploading a file)
using POST.
Since the data sent by the POST method is not visible in the URL, so it
is not possible to bookmark the page with specific query.
Like $_GET, PHP provide another superglobal variable $_POST to
access all the information sent via post method or submitted through
an HTML form using the method="post".

<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of PHP POST method</title>
</head>
<body>
<?php
if(isset($_POST["name"])){
echo "<p>Hi, " . $_POST["name"] . "</p>";
}
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<label for="inputName">Name:</label>
<input type="text" name="name" id="inputName">
<input type="submit" value="Submit">
</form>
</body>

2. Form Attribute

action - This attribute specifies a form processing agent. User agent behavior for
a value other than an HTTP URI is undefined.

method - get|post This attribute specifies which HTTP method will be used to
submit the form data set. Possible (case-insensitive) values are "get" (the
default) and "post". See the section on form submission for usage information.

enctype - This attribute specifies the content type used to submit the form to the
server (when the value of method is "post"). The default value for this attribute
is "application/x-www-form-urlencoded". The value "multipart/form-data" should
be used in combination with the INPUT element, type="file".

2
accept-charset - charset list This attribute specifies the list of character
encodings for input data that is accepted by the server processing this form. The
value is a space- and/or comma-delimited list of charset values. The client must
interpret this list as an exclusive-or list, i.e., the server is able to accept any
single character encoding per entity received.

The default value for this attribute is the reserved string "UNKNOWN". User
agents may interpret this value as the character encoding that was used to
transmit the document containing this FORM element.

accept = content-type-list This attribute specifies a comma-separated list of


content types that a server processing this form will handle correctly. User agents
may use this information to filter out non-conforming files when prompting a user
to select files to be sent to the server (cf. the INPUT element when type="file").
name = cdata [CI]
This attribute names the element so that it may be referred to from style sheets
or scripts. Note. This attribute has been included for backwards compatibility.
Applications should use the id attribute to identify elements.

3. CSS Colors

CSS has several options for defining colors of both text and background areas on
your pages.

These options can entirely replace the color attributes in plain HTML. In addition,
you get new options that you just didn't have in plain HTML.

For example, in plain HTML, when you wanted to create an area with a specific
color you were forced to include a table. With CSS, you can define an area to
have a specific color without that area being part of a table.

Or even more useful, in plain HTML when working with tables, you had to specify
font attributes and colors etc. for each and every table cell. With CSS you can
simply refer to a certain class in your <TD> tags.

COLOR PROPERTIES

Property Values NS IE
Color <color> 4+ 4+
transparent 4+ 4+
background-color
<color> 4+ 4+
none 4+ 4+
background-image
url(<URL>) 4+ 4+
repeat 4+ 4+
repeat-x 4+ 4+
background-repeat
repeat-y 4+ 4+
no-repeat 4+ 4+
scroll 4+
background-attachment
fixed 4+
background-position <percentage> 4+
<length> 4+
top 4+
center 4+

3
bottom 4+
left 4+
right 4+
<background-color> 4+ 4+
<background-image> 4+ 4+
background <background-repeat> 4+ 4+
<background-attachment> 4+
<background-position> 4+

Setting colors

Basically you have three color options with CSS:

1: Setting the foreground color for contents


2: Setting the background color for an area
3: Setting a background image to fill out an area

In the next section we will list the different properties that let you
do that.

In plain HTML, colors can either be entered by name (red, blue etc.) or by a
hexadecimal color code (for example: #FF9900).

With CSS you have these options:

Common name
You can define colors with the use of common names, by
simply enter the name of the desired color.

For example:

.myclass {color:red; background-color:blue;}

Hexadecimal value
You can define colors with the use of hexadecimal values,
similar to how it's done in plain HTML.

For example:

.myclass {color:#000000; background-color:#FFCC00;}

RGB value
You can define colors with the use of RGB values, by simply
entering the values for amounts of Red, Green and Blue.

4
For example:

.myclass {color:rgb(255,255,204); background-


color:rgb(51,51,102);}

You can also define RGB colors using percentage values for
the amounts of Red, Green and Blue:

For example:

.myclass {color:rgb(100%,100%,81%); background-


color:rgb(81%,18%,100%);}

Setting background colors

Background colors are defined similar to the colors mentioned above. For example you
can set the background color of the entire page using the BODYselector:

BODY {background-color:#FF6666;}

Setting a background image


CSS lets you set a background image for both the page and single elements on the
page.

In addition, CSS offers several positioning methods for background images.

You can define the background image for the page like this:
BODY {background-image:url(myimage.gif);}

You can control the repetition of the image with the background-repeatproperty.

background-repeat:repeat
Tiles the image until the entire page is filled, just like an
ordinary background image in plain HTML.

background-repeat:repeat-x
Repeats the image horizontally - but not vertically.

background-repeat:repeat-y
Repeats the image vertically - but not horizontally.

background-repeat:no-repeat
Does not tile the image at all.

Positioning a background
5
Background positioning is done by entering a value for the left position and top position
separated by a space.

In this example the image is positioned 75 pixels from the upper left corner of the page:

BODY {background-image:url(myimage.gif); background-


position: 75px 75px;}

Note: Background positioning is not supported by Netscape 4 browsers.

Fixing a background
You can fixate an image at a certain position so that it doesn't move when scrolling
occurs.

BODY {background-image:url(myimage.gif); background-


attachment: fixed;}

Note: Background fixation is not supported by Netscape 4 browsers.

Setting multiple background values


Rather than defining each background property with its own property you can assign
them all with the use of the background property.

Look at this example:

BODY {background:green url(myimage.gif) repeat-y fixed 75px


75px;}

CSS NTH

EVEN AND ODD RULES

One way to improve the readability of large tables is to color alternating rows. For
example, the table below has a light gray background for the even rows and white for
the odd ones. The rules for that are extremely simple:

tr:nth-child(even) {background: #CCC}


tr:nth-child(odd) {background: #FFF}
Month '94 '95 '96 '97 '98 '99 '00 '01 '02
Jan 14 13 14 13 14 11 11 11 11
Feb 13 15 12 15 15 12 14 13 13
Mar 16 15 14 17 16 15 14 15 15
Apr 17 16 17 17 17 15 15 16 16
May 21 20 20 21 22 20 21 20 19
Jun 24 23 25 24 25 23 25 23 24
Jul 29 28 26 26 27 26 25 26 25

6
Aug 29 28 27 28 28 27 26 28 26
Sep 24 23 23 26 24 24 24 22 21
Oct 20 22 20 22 20 19 20 22
Nov 18 17 16 17 16 15 14 15
Dec 15 13 13 14 13 10 13 11

In fact, CSS allows not only allow even/odd alternations, but arbitrary intervals. The
keywords 'even' and 'odd' are just convenient shorthands. For example, for a long list
you could do this:

li:nth-child(5n+3) {font-weight: bold}

This says that every 5th list item is bold, starting with the 3rd one. In other words, the
items numbered 3, 8, 13, 18, 23, etc., will be bold.

EVEN AND ODD COLUMNS

The same works for table columns, too, but then there has to be an element in the
document that corresponds to the column. HTML provides COL for that. The table has
to start with one COL for every column:

<table>
<col><col><col><col><col><col><col><col><col><col>
<tr><th>Month<th>'94<th>'95<th>'96...

(COL can be used for other things than style, but in this case all we need is that the
COL elements are present.) The following rules give the first column a yellow
background, and then every second column starting from column 3 a gray one:

col:first-child {background: #FF0}


col:nth-child(2n+3) {background: #CCC}
Month '94 '95 '96 '97 '98 '99 '00 '01 '02
Jan 14 13 14 13 14 11 11 11 11
Feb 13 15 12 15 15 12 14 13 13
Mar 16 15 14 17 16 15 14 15 15
Apr 17 16 17 17 17 15 15 16 16
May 21 20 20 21 22 20 21 20 19
Jun 24 23 25 24 25 23 25 23 24
Jul 29 28 26 26 27 26 25 26 25
Aug 29 28 27 28 28 27 26 28 26
Sep 24 23 23 26 24 24 24 22 21
Oct 20 22 20 22 20 19 20 22
Nov 18 17 16 17 16 15 14 15
Dec 15 13 13 14 13 10 13 11

The background of rows (TR) is drawn in front of the background of columns (COL), so
if you want to be sure that the background of the columns is visible, you should not set a
background on the rows.

Sources:

7
http://www.tutorialrepublic.com/php-tutorial/php-get-and-post.php

https://www.w3.org/TR/html401/interact/forms.html

https://developer.mozilla.org/en/docs/Web/CSS/color_value

https://www.w3.org/Style/Examples/007/evenodd.en.html

Das könnte Ihnen auch gefallen