Web Programming I - Week 4: Mikheil Rukhaia
Web Programming I - Week 4: Mikheil Rukhaia
Mikheil Rukhaia
Outline
1 Forms
2 Form Controls
3 Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 2 / 49
Forms Form Controls Laboratory Work
Forms
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 3 / 49
Forms Form Controls Laboratory Work
Introducing forms
I HTML can create forms, but what happens with the form data is
a job of server-side scripting languages, like PHP.
I Forms can contain any HTML elements used before, but not
<form> element again (i.e. forms cannot be nested).
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 4 / 49
Forms Form Controls Laboratory Work
I Every form must contain the submit button (actual text on the
button can be different).
I After clicking the submit button (or the enter key) data is sent to
the server in name/value pairs.
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 5 / 49
Forms Form Controls Laboratory Work
Simple form
I Example:
<form action="search.php" method="get">
Search:
<input type="text" name="txtSearch" />
<input type="submit" value="Search" />
</form>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 6 / 49
Forms Form Controls Laboratory Work
Attributes of <form>
I Get method sends data as part of the URL (directly visible, can
be bookmarked).
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 7 / 49
Forms Form Controls Laboratory Work
I Example: onsubmit="validateForm();"
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 8 / 49
Forms Form Controls Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 9 / 49
Forms Form Controls Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 10 / 49
Forms Form Controls Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 11 / 49
Forms Form Controls Laboratory Work
Form Controls
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 12 / 49
Forms Form Controls Laboratory Work
HTML5 forms
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 13 / 49
Forms Form Controls Laboratory Work
Backward compatibility
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 14 / 49
Forms Form Controls Laboratory Work
Main controls
I Buttons.
I Hidden controls.
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 15 / 49
Forms Form Controls Laboratory Work
Text inputs
I Single-line text input: item that requires only one line of user
input (search boxes, e-mail addresses, etc.) and is created using
the <input> element.
I Password input: the same as the single-line text input, but masks
the characters (usually via *) so that they cannot be seen on the
screen.
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 16 / 49
Forms Form Controls Laboratory Work
Attribute Description
name the name part of the name/value pair that is
sent to the server (it is a good practice to start
names of the text-input control with txt).
value an initial value that the user will see when the
form loads.
size the width of the text-input control in terms of
characters (does not affect how many charac-
ters users can enter).
maxlength the maximum number of characters a user can
enter.
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 17 / 49
Forms Form Controls Laboratory Work
I Example:
<input type="text" list="browsers" />
<datalist id="browsers">
<option value="Internet Explorer" />
<option value="Firefox" />
<option value="Chrome" />
<option value="Opera" />
<option value="Safari" />
</datalist>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 19 / 49
Forms Form Controls Laboratory Work
Password input
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 20 / 49
Forms Form Controls Laboratory Work
I Example:
<textarea name="txtArea" rows="20" cols="50">
This text is shown inside the form.
</textarea>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 21 / 49
Forms Form Controls Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 22 / 49
Forms Form Controls Laboratory Work
Buttons
I Example:
<input type="reset" value="Reset" />
<input type="button" value="Cancel"
onclick="cancel()" />
<input type="submit" value="Submit" />
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 23 / 49
Forms Form Controls Laboratory Work
Buttons (ctd.)
I Example:
<input type="image" src="submit.gif"
alt="Submit" />
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 24 / 49
Forms Form Controls Laboratory Work
Buttons (ctd.)
I Example:
<button type="reset">Reset</button>
<button type="button" onclick="cancel()">
<img src="cancel.gif" alt="Cancel" />
</button>
<button type="submit"><b>Submit</b></button>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 25 / 49
Forms Form Controls Laboratory Work
Checkboxes
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 26 / 49
Forms Form Controls Laboratory Work
Checkboxes (ctd.)
I Example:
<input type="checkbox" name="chk"
value="xml" /> XML <br />
<input type="checkbox" name="chk"
value="html" /> HTML <br />
<input type="checkbox" name="chk"
value="css" /> CSS <br />
<input type="checkbox" name="chk"
value="js" /> JavaScript <br />
<input type="checkbox" name="chk"
value="php" /> PHP <br />
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 27 / 49
Forms Form Controls Laboratory Work
Radio buttons
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 28 / 49
Forms Form Controls Laboratory Work
I Example:
<input type="radio" name="rad"
value="xml" /> XML <br />
<input type="radio" name="rad"
value="html" /> HTML <br />
<input type="radio" name="rad"
value="css" /> CSS <br />
<input type="radio" name="rad"
value="js" /> JavaScript <br />
<input type="radio" name="rad"
value="php" /> PHP <br />
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 29 / 49
Forms Form Controls Laboratory Work
Select boxes
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 30 / 49
Forms Form Controls Laboratory Work
I Example:
<select name="sel">
<option value=""> --- </option>
<option value="xml"> XML </option>
<option value="html"> HTML </option>
<option value="css"> CSS </option>
<option value="js"> JavaScript </option>
<option value="php"> PHP </option>
</select>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 31 / 49
Forms Form Controls Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 32 / 49
Forms Form Controls Laboratory Work
I Example:
<select name="sel">
<option value=""> --- </option>
<optgroup label="Markup">
<option value="xml"> XML </option>
<option value="html"> HTML </option>
</optgroup>
<optgroup label="Style">
<option value="css"> CSS </option>
</optgroup>
<optgroup label="Scripting">
<option value="js"> JavaScript </option>
<option value="php"> PHP </option>
</optgroup>
</select>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 33 / 49
Forms Form Controls Laboratory Work
I Example:
<form action="upload.php" name="upForm"
method="post"
enctype="multipart/form-data">
<input type="file" name="fileUpload"
accept="image/*" />
<br /><br />
<input type="submit" value="Submit" />
</form>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 34 / 49
Forms Form Controls Laboratory Work
Hidden controls
I Used to pass data between pages without the user seeing it (still
visible in source code).
I Example:
<input type="hidden" name="hidItem"
value="hidValue" />
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 35 / 49
Forms Form Controls Laboratory Work
I datetime for entering a date and time with the time zone.
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 37 / 49
Forms Form Controls Laboratory Work
Fancy elements
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 38 / 49
Forms Form Controls Laboratory Work
I Example:
<progress value="14" max="20"></progress>
<progress name="indeterminate"></progress>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 39 / 49
Forms Form Controls Laboratory Work
I Example:
<meter min="0" value="95" high="90" max="100">
</meter>
<meter min="0" value="50" high="90" max="100">
</meter>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 40 / 49
Forms Form Controls Laboratory Work
I Private key is stored locally, and public key is sent to the server.
I Example:
<keygen name="certificate" />
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 41 / 49
Forms Form Controls Laboratory Work
I Example:
0
<input type="range" name="a" value="50"
onchange="x.value=parseInt(a.value)+
parseInt(b.value)" />
100 +
<input type="number" name="b" value="50" />
=
<output name="x" for="a b"></output>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 42 / 49
Forms Form Controls Laboratory Work
Fancy forms
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 43 / 49
Forms Form Controls Laboratory Work
I Example:
<fieldset>
<legend>We learned</legend>
<input type="checkbox" name="chk"
value="xml" /> XML <br />
<input type="checkbox" name="chk"
value="html" /> HTML <br />
<input type="checkbox" name="chk"
value="css" /> CSS <br />
<input type="checkbox" name="chk"
value="js" /> JavaScript <br />
<input type="checkbox" name="chk"
value="php" /> PHP <br />
</fieldset>
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 44 / 49
Forms Form Controls Laboratory Work
Common attributes
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 45 / 49
Forms Form Controls Laboratory Work
readonly disabled
Can be modified by script, not by user by script, not by user
Will be sent to server yes not while disabled
Will receive focus yes no
Included in tabbing order yes no
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 46 / 49
Forms Form Controls Laboratory Work
Laboratory Work
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 47 / 49
Forms Form Controls Laboratory Work
Exercises
A file upload box and a select box to choose purpose of the file
(CV, picture, certificate, transcripts).
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 48 / 49
Forms Form Controls Laboratory Work
Discussion?!
Web Programming I — Week 4 M. Rukhaia International Black Sea University September 17, 2018 49 / 49