Академический Документы
Профессиональный Документы
Культура Документы
What is HTML?
Example:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
HTML
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read HTML documents
and display them.
The browser does not display the HTML tags, but uses them to determine how to display
the document:
HTML Documents
All HTML documents must start with a document type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
HTML Forms
The HTML <form> element defines a form that is used to collect user input:
<form>
.
form elements
.
</form>
An HTML form contains form elements.
Form elements are different types of input elements, like text fields, checkboxes, radio
buttons, submit buttons, and more.
HTML Forms
Examples:
<input type="text"> Defines a one-line text input field
<input type="radio"> Defines a radio button (for selecting one of many choices)
<input type="submit"> Defines a submit button (for submitting the form)
HTML Forms
Example:
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
HTML Forms
Example:
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
HTML Forms
<input type="submit"> defines a button for submitting the form data to a form-handler.
The form-handler is typically a server page with a script for processing input data.
The form-handler is specified in the form's action attribute.
Example:
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
HTML Forms
The action attribute defines the action to be performed when the form is submitted.
Normally, the form data is sent to a web page on the server when the user clicks on the
submit button.
Example:
<form action="/action_page.php">
If the action attribute is omitted, the action is set to the current page.
HTML Forms
The target attribute specifies if the submitted result will open in a new browser tab, a
frame, or in the current window.
The default value is "_self" which means the form will be submitted in the current window.
To make the form result open in a new browser tab, use the value "_blank“.
Example:
<form action="/action_page.php" target="_blank">
Other legal values are "_parent", "_top", or a name representing the name of an iframe.
HTML Forms
The method attribute specifies the HTTP method (GET or POST) to be used when submitting
the form data.
Example:
<form action="/action_page.php" method="get">
or
<form action="/action_page.php" method="post">
HTML Forms
Notes on GET:
Appends form-data into the URL in name/value pairs
The length of a URL is limited (about 3000 characters)
Never use GET to send sensitive data! (will be visible in the URL)
GET is better for non-secure data, like query strings in Google
HTML Forms
Notes on POST:
POST has no size limitations, and can be used to send large amounts of data.
HTML Forms
Example:
<form action="/action_page.php">
First name:<br>
<input type="text" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
HTML Forms
Example:
<form action="/action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
HTML Forms
HTML Form Elements
Example:
<input name="firstname" type="text">
If the type attribute is omitted, the input field gets the default type: "text“.
HTML Form Elements
Example:
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
HTML Form Elements
Example:
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
HTML Form Elements
Example:
<select name="cars“ size=“3”>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
HTML Form Elements
Example:
<select name="cars“ size=“3” multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
HTML Form Elements
Example:
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
The rows attribute specifies the visible number of lines in a text area.
The cols attribute specifies the visible width of a text area.
HTML Form Elements
You can also define the size of the text area by using CSS.
Example:
<textarea name="message" style="width:200px; height:600px;">
The cat was playing in the garden.
</textarea>
HTML Form Elements
Example:
<button type="button" onclick="alert('Hello World!')">Click Me!</button>
HTML Form Elements
Example:
<form action="/action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
HTML Form Elements
Tag Description
<form> Defines an HTML form for user input
<input> Defines an input control
<textarea> Defines a multiline input control (text area)
<label> Defines a label for an <input> element
<fieldset> Groups related elements in a form
<legend> Defines a caption for a <fieldset> element
<select> Defines a drop-down list
<optgroup> Defines a group of related options in a drop-down list
<option> Defines an option in a drop-down list
<button> Defines a clickable button
<datalist> Specifies a list of pre-defined options for input controls
HTML Input Types
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
HTML Input Types
Example:
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
HTML Input Types
Example:
<form>
User name:<br>
<input type="text" name="username"><br>
User password:<br>
<input type="password" name="psw">
</form>
HTML Input Types
The form-handler is typically a server page with a script for processing input data.
The form-handler is specified in the form's action attribute:
Example:
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
HTML Input Types
Example:
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
HTML Input Types
Example:
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
HTML Input Types
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example:
<form>
<input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle2" value="Car"> I have a car
</form>
HTML Input Types
Example:
<input type="button" onclick="alert('Hello World!')" value="Click Me!">
HTML Input Types
Example:
<form>
Select your favorite color:
<input type="color" name="favcolor">
</form>
HTML Input Types
Example:
<form>
Birthday:
<input type="date" name="bday">
</form>
HTML Input Types
You can also use the min and max attributes to add restrictions to dates:
Example:
<form>
Enter a date before 1980-01-01:
<input type="date" name="bday" max="1979-12-31"><br>
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02"><br>
</form>
HTML Input Types
Example:
<form>
Birthday (date and time):
<input type="datetime-local" name="bdaytime">
</form>
HTML Input Types
Example:
<form>
E-mail:
<input type="email" name="email">
</form>
HTML Input Types
Example:
<form>
Select a file: <input type="file" name="myFile">
</form>
HTML Input Types
Example:
<form>
Birthday (month and year):
<input type="month" name="bdaymonth">
</form>
HTML Input Types
Example:
<form>
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
</form>
HTML Input Types
Example:
<form>
<input type="range" name="points" min="0" max="10">
</form>
HTML Input Types
Example:
<form>
Search Google:
<input type="search" name="googlesearch">
</form>
HTML Input Types
Example:
<form>
Telephone:
<input type="tel" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
</form>
HTML Input Types
Example:
<form>
Select a time:
<input type="time" name="usr_time">
</form>
HTML Input Types
Example:
<form>
Add your homepage:
<input type="url" name="homepage">
</form>
HTML Input Types
Example:
<form>
Select a week:
<input type="week" name="week_year">
</form>
HTML Input Types
Input Restrictions
Attribute Description
checked Specifies that an input field should be pre-selected when the page loads (for type="checkbox" or type="radio")
disabled Specifies that an input field should be disabled
max Specifies the maximum value for an input field
maxlength Specifies the maximum number of character for an input field
min Specifies the minimum value for an input field
pattern Specifies a regular expression to check the input value against
readonly Specifies that an input field is read only (cannot be changed)
required Specifies that an input field is required (must be filled out)
size Specifies the width (in characters) of an input field
step Specifies the legal number intervals for an input field
value Specifies the default value for an input field
HTML Input Attributes
Example:
<form action="">
First name:<br>
<input type="text" name="firstname" value="John">
</form>
HTML Input Attributes
Example:
<form action="">
First name:<br>
<input type="text" name="firstname" value="John" readonly>
</form>
HTML Input Attributes
Example:
<form action="">
First name:<br>
<input type="text" name="firstname" value="John" disabled>
</form>
HTML Input Attributes
Example:
<form action="">
First name:<br>
<input type="text" name="firstname" value="John" size="40">
</form>
HTML Input Attributes
Example:
<form action="">
First name:<br>
<input type="text" name="firstname" maxlength="10">
</form>
HTML Input Attributes
Example:
<form action="/action_page.php" autocomplete="on">
First name:<input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
E-mail: <input type="email" name="email" autocomplete="off"><br>
<input type="submit">
</form>
HTML Input Attributes
Example:
<form action="/action_page.php" novalidate>
E-mail: <input type="email" name="user_email">
<input type="submit">
</form>
HTML Input Attributes
Example:
First name:<input type="text" name="fname" autofocus>
HTML Input Attributes
Example:
<input type="text" name="fname" placeholder="First name">
PHP
What is PHP?
PHP is an acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source scripting language
PHP scripts are executed on the server
PHP is free to download and use
PHP
<?php
// PHP code goes here
?>
Example:
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
PHP Variables
Example:
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
PHP Variables
A variable can have a short name (like x and y) or a more descriptive name (age,
carname, total_volume).
The PHP echo statement is often used to output data to the screen.
Example: Example 2:
<?php <?php
$txt = "W3Schools.com"; $x = 5;
echo "I love $txt!"; $y = 4;
?> echo $x + $y;
?>
or
<?php
$txt = "W3Schools.com";
echo "I love " . $txt . "!";
?>
PHP Variable Scope
A variable declared outside a function has a GLOBAL SCOPE and can only be accessed
outside a function.
Example:
<?php
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
echo "<p>Variable x outside function is: $x</p>";
?>
PHP Variable Scope
A variable declared within a function has a LOCAL SCOPE and can only be accessed within
that function.
Example:
<?php
function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
PHP Global keyword
The global keyword is used to access a global variable from within a function.
Example:
<?php
$x = 5;
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest();
echo $y; // outputs 15
?>
PHP Global keyword
PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the
name of the variable. This array is also accessible from within functions and can be used to
update global variables directly.
Example:
<?php
$x = 5;
$y = 10;
function myTest() {
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
}
myTest();
echo $y; // outputs 15
?>
PHP Forms
The PHP superglobals $_GET and $_POST are used to collect form-data.
Example 1 (POST):
<html>
<body>
</body>
</html>
PHP Forms
</body>
</html>
PHP Forms
Example 2 (GET):
<html>
<body>
</body>
</html>
PHP Forms
</body>
</html>