Wit Unit Iv Pmfa

Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Web & Internet technologies UNIT-IV XML, Creating & Using forms

UNIT – IV

Creating and Using Forms: Understanding Common Form Issues, GET vs. POST, Validating
form input, Working with multiple forms, and Preventing Multiple Submissions of a form.

XML: Basic XML- Document Type Definition XML Schema DOM and Presenting XML, XML
Parsers and Validation, XSL and XSLT Transformation, News Feed (RSS and ATOM).

XML
Basic XML:

Extensible Markup Language (XML) is a markup language that defines a set of rules for
encoding documents in a format that is both human-readable and machine-readable. The W3C's
XML 1.0 Specification and several other related specifications —all of them free open standards.

The design goals of XML emphasize simplicity, generality, and usability across the Internet.

• XML stands for eXtensible Markup Language.


• XML was designed to store and transport data.
• XML was designed to be both human- and machine-readable.
• XML is a software- and hardware-independent tool for storing and transporting
data.

What is XML?

• XML stands for eXtensible Markup Language


• XML is a markup language much like HTML
• XML was designed to store and transport data
• XML was designed to be self-descriptive
• XML is a W3C Recommendation
The Difference between XML and HTML

• XML was designed to carry data - with focus on what data is


• HTML was designed to display data - with focus on how data looks
• XML tags are not predefined like HTML tags are
XML Does Not Use Predefined Tags

• The XML language has no predefined tags.


• Tags are "invented" by the author of the XML document.
• HTML works with predefined tags like <p>, <h1>, <table>, etc.
• With XML, the author must define both the tags and the document structure.

XML is Extensible

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 1
Web & Internet technologies UNIT-IV XML, Creating & Using forms

XML Simplifies Things

• It simplifies data sharing


• It simplifies data transport
• It simplifies platform changes
• It simplifies data availability
XML stores data in plain text format. This provides a software- and hardwareindependent
way of storing, transporting, and sharing data.

XML also makes it easier to expand or upgrade to new operating systems, new applications,
or new browsers, without losing data.

With XML, data can be available to all kinds of "reading machines" like people, computers,
voice machines, news feeds, etc

How Can XML be used?

• XML is used in many aspects of web development.


• XML is often used to separate data from presentation.
XML Separates Data from Presentation

• XML does not carry any information about how to be displayed.


• The same XML data can be used in many different presentation scenarios. Because
of this, with XML, there is a full separation between data and presentation.

XML is Often a Complement to HTML

In many HTML applications, XML is used to store or transport data, while HTML is used
to format and display the same data.

XML Separates Data from HTML

When displaying data in HTML, you should not have to edit the HTML file when the data
changes. With XML, the data can be stored in separate XML files

XML Example

XML documents create a hierarchical structure looks like a tree so it is known as XML
Tree that starts at "the root" and branches to "the leaves".

<?xml version="1.0" encoding="ISO-8859-1"?>

<student>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 2
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<name>Rahul</name>

<rollno>17KH1A0589</rollno>

<yearsem>III-II</yearsem>

<branch>CSE</branch>

</student> Output:

The first line is the XML declaration. It defines the XML version (1.0) and the encoding
used (ISO-8859-1 = Latin-1/West European character set).

The next line describes the root element of the document (like saying: "this document is a
student"):

<student>

The next 4 lines describe 4 child elements of the root (name, rollno, yearsem, branch).And
finally the last line defines the end of the root element.

</student>

XML documents must contain a root element. This element is "the parent" of all other
elements. The elements in an XML document form a document tree. The tree starts at the root and
branches to the lowest level of the tree. All elements can have sub elements (child elements).
<root>

<child>

<subchild>.....</subchild>

</child>

</root>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 3
Web & Internet technologies UNIT-IV XML, Creating & Using forms

The terms parent, child, and sibling are used to describe the relationships between elements.
Parent elements have children. Children on the same level are called siblings (brothers or sisters).
All elements can have text content and attributes (just like in HTML).

// XML Document to create a catalogue of books & laptops

<?xml version="1.0" encoding="ISO-8859-1"?>


<catalogue>
<books>
<book category="Programming">
<title>Java The Complete Reference</title>
<author>Herbert Schildt</author>
<price>700</price>
</book>
<book category="Algorithms">
<title>Data Structures</title>
<author>Debasis Samanta</author>
<price>500</price>
</book>
<book category="Programming">
<title>C The Complete Reference</title>
<author>Herbert Schilde</author>
<price>800</price>
</book>
</books>
<laptops>
<laptop>
<brand>Acer</brand>
<HDD>1TB</HDD>

<RAM>4GB</RAM>
<price>27500</price>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 4
Web & Internet technologies UNIT-IV XML, Creating & Using forms

</laptop>
<laptop>
<brand>Lenovo</brand>
<HDD>500GB</HDD>
<RAM>8GB</RAM>
<price>23000</price>
</laptop>
</laptops>
</catalogue>
The root element in the example is <catalogue>. All elements in the document are
contained within < catalogue >. <books> & <laptops> elements are siblings to each other and
children of <catalogue>. <book> is child of <books> and it has 3 children <title>, <author> &
<price>. The <laptop> element has 4 children: <brand>,< HDD>, <RAM> and <price>.

Output:

XML Syntax:

XML Documents Must Have a Root Element

XML documents must contain one root element that is the parent of all other elements.

The XML Prolog

This line is called the XML prolog:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 5
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<?xml version="1.0" encoding="UTF-8"?>

The XML prolog is optional. If it exists, it must come first in the document. XML
documents can contain international characters, like Norwegian øæå or French êèé. To avoid
errors, you should specify the encoding used, or save your XML files as UTF-8.

All XML Elements Must Have a Closing Tag

In XML, it is illegal to omit the closing tag. All elements must have a closing tag:

XML Tags are Case Sensitive

XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and closing
tags must be written with the same case:

XML Elements Must be Properly Nested

In HTML, you might see improperly nested elements:

<b><i>This text is bold and italic</b></i>

In XML, all elements must be properly nested within each other:

<b><i>This text is bold and italic</i></b>

In the example above, "Properly nested" simply means that since the <i> element is opened
inside the <b> element, it must be closed inside the <b> element.

XML Attribute Values Must Always be Quoted

XML elements can have attributes in name/value pairs just like in HTML. In XML, the
attribute values must always be quoted:

<book category="Programming">
Comments in XML

The syntax for writing comments in XML is similar to that of HTML:

<!-- This is a comment -->

Two dashes in the middle of a comment are not allowed:

<!-- This is an invalid -- comment -->

White-space is Preserved in XML

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 6
Web & Internet technologies UNIT-IV XML, Creating & Using forms

XML does not truncate multiple white-spaces (HTML truncates multiple white-spaces to
one single white-space):

XML: Hello Tove

HTML: Hello Tove

XML Element:

An XML element is everything from (including) the element's start tag to (including) the element's
end tag.

<price>700</price>

An element can contain:

• text
• attributes
• other elements
• or a mix of the above

In the catalogue example above:

<title>, <author> and <price> have text content because they contain text (like 700).
<catalogue> and <books> have element contents, because they contain elements.<book> has an
attribute (category="children").

Empty XML Elements

An element with no content is said to be empty.

<element> </element> or <element/>

XML Naming Rules

XML elements must follow these naming rules:

• Element names are case-sensitive


• Element names must start with a letter or underscore

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 7
Web & Internet technologies UNIT-IV XML, Creating & Using forms

• Element names cannot start with the letters xml (or XML, or Xml, etc)
Element names can contain letters, digits, hyphens, underscores, and periods
Element names cannot contain spaces.

Any name can be used, no words are reserved (except xml).

XML Elements are Extensible

XML elements can be extended to carry more information.

Look at the following XML example:

<?xml version="1.0" encoding="ISO-8859-1"?>

<student>

<name>Rahul</name>

<rollno>17KH1A0589</rollno>

<yearsem>III-II</yearsem>

<branch>CSE</branch>

</student>

We created an application that extracted the <name>, <rollno>,<yearsem> and <branch>


elements from the XML document. Later, we want to add some extra information to it.

<student>

<name>Rahul</name>

<fathername>Rohan</fathername>

<rollno>17KH1A0589</rollno>

<yearsem>III-II</yearsem>

<branch>CSE</branch>

<address>Kadapa</address>

</student>

Should the application break or crash?

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 8
Web & Internet technologies UNIT-IV XML, Creating & Using forms

No. The application should still be able to find the <name>, <rollno>,<yearsem> and <branch>
elements in the XML document and produce the same output.

XML Attributes

XML elements can have attributes, just like HTML. Attributes are designed to contain data related
to a specific element.

XML Attributes Must be Quoted

Attribute values must always be quoted. Either single or double quotes can be used. For a
person's gender, the <person> element can be written like this:

<person gender="female"> or <person gender="male">

If the attribute value itself contains double quotes you can use single quotes, like in this
example:

<address stname=’Krishna “Theater” Circle’>

XML Elements Vs Attributes


Ex1: Ex2:
<person gender=”male”> <person>
<fname>Karhik</fname> <gender>male</gender>
<lname>Pula</lname> <fname>Karhik</fname>
</person> <lname>Pula</lname>
</person>

In the first example gender is an attribute. In the second example, gender is an element.
Both examples provide the same information. There are no rules about when to use attributes or
when to use elements in XML.

Some things to consider when using attributes are:

• attributes cannot contain multiple values (elements can)


• attributes cannot contain tree structures (elements can)
• attributes are not easily expandable (for future changes)

XML Attributes for Metadata

Sometimes ID references are assigned to elements. These IDs can be used to identify XML
elements in much the same way as the id attribute in HTML. This example demonstrates this:

<laptops>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 9
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<laptop id=”501”>
<brand>Acer</brand> <HDD>1TB</HDD>
<RAM>4GB</RAM>
<price>27500</price>
</laptop>
<laptop id=”502”>
<brand>Lenovo</brand>
<HDD>500GB</HDD>
<RAM>8GB</RAM>
<price>23000</price>
</laptop>
</laptops>
The id attributes above are for identifying the different laptops. It is not a part of the laptop
itself. Metadata (data about data) should be stored as attributes, and the data itself should be stored
as elements.

Document Type Definition:

A DTD is a Document Type Definition. A DTD defines the structure and the legal elements and
attributes of an XML document.

Why Use a DTD?

• With a DTD, independent groups of people can agree on a standard DTD for interchanging
data.
• An application can use a DTD to verify that XML data is valid.

An Internal DTD Declaration


If the DTD is declared inside the XML file, it must be wrapped inside the <!DOCTYPE>
definition:

//Ex: studentidtd.xml

<?xml version="1.0"?>
<!DOCTYPE student [
<!ELEMENT student (name,rollno,yearsem,branch)>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 10
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<!ELEMENT name (#PCDATA)>


<!ELEMENT rollno (#PCDATA)>
<!ELEMENT yearsem (#PCDATA)>
<!ELEMENT branch (#PCDATA)>

]>
<student>
<name>Rohan</name>
<rollno>17KH1A0589</rollno>
<yearsem>III-II</yearsem>
<branch>CSE</branch>

</student> Output:

The DTD above is interpreted like this:

• !DOCTYPE student defines that the root element of this document is student
• !ELEMENT student defines that the student element must contain four elements:
"name,rollno,yearsem,branch"
• !ELEMENT name defines the name element to be of type "#PCDATA"
• !ELEMENT rollno defines the rollno element to be of type "#PCDATA"
• !ELEMENT yearsem defines the yearsem element to be of type "#PCDATA"
• !ELEMENT branch defines the branch element to be of type "#PCDATA"

An External DTD Declaration


If the DTD is declared in an external file, the <!DOCTYPE> definition must contain a reference
to the DTD file: Studentedtd.xml

<?xml version="1.0"?>

<!DOCTYPE student SYSTEM "std.dtd">

<student>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 11
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<name>Rohan</name>

<rollno>17KH1A0589</rollno>

<yearsem>III-II</yearsem>

<branch>CSE</branch>

</student>

//std.dtd

<!ELEMENT student (name,rollno,yearsem,branch)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT rollno (#PCDATA)>

<!ELEMENT yearsem (#PCDATA)>

<!ELEMENT branch (#PCDATA)>

DTD - XML Building Blocks

From DTD point of view, all XML documents are made up by the following building
blocks:

• Elements
• Attributes
• Entities
• PCDATA
• CDATA
Elements

Elements are the main building blocks of both XML and HTML documents.

Examples of HTML elements are "body" and "table". Examples of XML elements could
be "student" and "book". Elements can contain text, other elements, or be empty. Examples of
empty HTML elements are "hr", "br" and "img".

Attributes

Attributes provide extra information about elements. Attributes are always placed inside
the opening tag of an element. Attributes always come in name/value pairs. The following "img"
element has additional information about a source file:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 12
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<img src="computer.gif" />

The name of the element is "img". The name of the attribute is "src". The value of the
attribute is "computer.gif". Since the element itself is empty it is closed by a " /".

Entities

Some characters have a special meaning in XML, like the less than sign (<) that defines the
start of an XML tag. The HTML entity: "&nbsp;". This "no-breaking-space" entity is used in
HTML to insert an extra space in a document. Entities are expanded when a document is parsed
by an XML parser.

The following entities are predefined in XML:

Entity References Character


&lt; <

&gt; >

&amp; &

&quot; "

&apos; '
PCDATA

PCDATA means parsed character data. Character data is the text found between the start
tag and the end tag of an XML element.

PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser
for entities and markup.

Tags inside the text will be treated as markup and entities will be expanded. However,
parsed character data should not contain any &, <, or > characters; these need to be represented by
the &amp; &lt; and &gt; entities, respectively.

CDATA

CDATA means character data.

CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be
treated as markup and entities will not be expanded.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 13
Web & Internet technologies UNIT-IV XML, Creating & Using forms

XML Schema:

An XML Schema describes the structure of an XML document, just like a DTD. An XML
document with correct syntax is called "Well Formed". An XML document validated against an
XML Schema is both "Well Formed" and "Valid".

XML Schema is an XML-based alternative to DTD. The XML Schema language is also referred
to as XML Schema Definition (XSD).

Visit http://www.xmlvalidation.com to validate the XML file against schema or DTD.

//studentschema.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="student">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="rollno" type="xs:string"/>
<xs:element name="yearsem" type="xs:string"/>
<xs:element name="branch" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
//stdntschma.xml

<?xml version="1.0"?>
<student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="studentschema.xsd">
<name>Rohan</name>
<rollno>17KH1A0589</rollno>

<yearsem>III-II</yearsem>
<branch>CSE</branch>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 14
Web & Internet technologies UNIT-IV XML, Creating & Using forms

</student> Output:

The Schema above is interpreted like this:

• <xs:element name="student"> defines the element called "student"


• <xs:complexType> the "student" element is a complex type
• <xs:sequence> the complex type is a sequence of elements
• <xs:element name="name" type="xs:string"> the element "name" is of type string (text)
• <xs:element name="rollno" type="xs:string"> the element "rollno" is of type string
• <xs:element name="yearsem" type="xs:string"> the element "yearsem" is of type string
• <xs:element name="branch" type="xs:string"> the element "branch" is of type string

XML Schemas are More Powerful than DTD

• XML Schemas are written in XML


• XML Schemas are extensible to additions
• XML Schemas support data types
• XML Schemas support namespaces
Why Use an XML Schema?

With XML Schema, your XML files can carry a description of its own format. With XML
Schema, independent groups of people can agree on a standard for interchanging data. With XML
Schema, you can verify data.

XML Schemas Support Data Types

One of the greatest strengths of XML Schemas is the support for data types:

• It is easier to describe document content


• It is easier to define restrictions on data
• It is easier to validate the correctness of data
• It is easier to convert data between different data types

XML Schemas use XML Syntax

Another great strength about XML Schemas is that they are written in XML:

• You don't have to learn a new language

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 15
Web & Internet technologies UNIT-IV XML, Creating & Using forms

• You can use your XML editor to edit your Schema files
• You can use your XML parser to parse your Schema files
• You can manipulate your Schemas with the XML DOM
• You can transform your Schemas with XSLT

XSD - The <schema> Element


The <schema> element is the root element of every XML Schema.

The <schema> element is the root element of every XML Schema:

<?xml version="1.0"?>
<xs:schema>
...
...
</xs:schema>

The <schema> element may contain some attributes. A schema declaration often looks something like
this:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com" xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
...
</xs:schema>

DTD vs XSD

There are many differences between DTD (Document Type Definition) and XSD (XML
Schema Definition). In short, DTD provides less control on XML structure whereas XSD (XML
schema) provides more control.
DTD XSD
DTD stands for Document Type Definition. XSD stands for XML Schema Definition.
DTDs are derived from SGML syntax. XSDs are written in XML.
DTD doesn't support datatypes. XSD supports datatypes for elements and
attributes.
DTD doesn't support namespace. XSD supports namespace.
DTD doesn't define order for child elements. XSD defines order for child elements.
DTD is not extensible. XSD is extensible.
DTD is not simple to learn. XSD is simple to learn because you don't need
to learn new language.
DTD provides less control on XML structure. XSD provides more control on XML
structure.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 16
Web & Internet technologies UNIT-IV XML, Creating & Using forms

XML – Namespaces:

A Namespace is a set of unique names. Namespace is a mechanisms by which element and


attribute name can be assigned to a group. The Namespace is identified by URI(Uniform Resource
Identifiers).

Namespace Declaration

A Namespace is declared using reserved attributes. Such an attribute name must either be
xmlns or begin with xmlns: shown as below −

<element xmlns:name = "URL">

Syntax

• The Namespace starts with the keyword xmlns.


• The word name is the Namespace prefix. The URL is the
Namespace identifier.

Example:

Namespace affects only a limited area in the document. An element containing the
declaration and all of its descendants are in the scope of the Namespace. Following is a simple
example of XML Namespace –

<dbs:book xmlns dbs=’http://www-dbs/dbs’>

dbs : Prefix as abbreviation of URI xmlns:

Signal that namespace definition happens

’http://www-dbs/dbs’ : Unique URI to identify the namespace.

DOM and Presenting XML Document Object Model

XML parsers can handle documents in any way that their developers choose. There are two
models commonly used for parsers i.e., SAX and DOM. SAX parsers are used when dealing with
streams of data. This type of parsers is usually used with java. SAX-based parsers run quickly.

DOM is and application program interface (API) for XML documents. The DOM API specifies
the logical structure of XML documents and the ways in which they can be accessed and
manipulated. The DOM API is just a specification. DOM-complaint applications include all of the
functionality needed to handle XML documents. They can build static documents, navigate and
search through them, add new elements, delete elements, and modify the content of existing
elements. The views XML document as trees. The DOM exposes the whole of the document to
applications. It is also scriptable so applications can manipulate the individual nodes.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 17
Web & Internet technologies UNIT-IV XML, Creating & Using forms

What is the DOM?

The DOM defines a standard for accessing and manipulating documents:

The HTML DOM defines a standard way for accessing and manipulating HTML
documents. It presents an HTML document as a tree-structure.

The XML DOM defines a standard way for accessing and manipulating XML documents.
It presents an XML document as a tree-structure.

Presenting XML

XML documents are presented using Extensible Stylesheet which expresses stylesheets. XSL
stylesheet are not the same as HTML cascading stylesheets. They create a style for a specific XML
element, with XSL a template is created. XSL basically transforms one data structure to another
i.e., XML to HTML.

XML Parsers:

All major browsers have a built-in XML parser to access and manipulate XML. The XML
DOM (Document Object Model) defines the properties and methods for accessing and editing
XML. However, before an XML document can be accessed, it must be loaded into an XML DOM
object. All modern browsers have a built-in XML parser that can convert text into an XML DOM
object.

An XML parser is a software library or package that provides interfaces for client
applications to work with an XML document. The XML Parser is designed to read the XML and
create a way for programs to use XML. XML parser validates the document and check that the
document is well formatted.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 18
Web & Internet technologies UNIT-IV XML, Creating & Using forms

Types of XML Parsers

These are the two main types of XML Parsers:

1. DOM
2. SAX

DOM (Document Object Model)


A DOM document is an object which contains all the information of an XML document. It
is composed like a tree structure. The DOM Parser implements a DOM API.

Features of DOM Parser


A DOM Parser creates an internal structure in memory which is a DOM document object
and the client applications get information of the original XML document by invoking methods on
this document object.

Advantages
• It supports both read and write operations and the API is very simple to use.

• It is preferred when random access to widely separated parts of a document is required.

Disadvantages
• It is memory inefficient. (consumes more memory because the whole XML document
needs to loaded into memory).

• It is comparatively slower than other parsers.

SAX (Simple API for XML)


A SAX Parser implements SAX API. This API is an event based API and less intuitive.

Features of SAX Parser


• It does not create any internal structure.
• Clients does not know what methods to call, they just overrides the methods of the API and
place his own code inside method.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 19
Web & Internet technologies UNIT-IV XML, Creating & Using forms

• It is an event based parser, it works like an event handler in Java.


Advantages
• It is simple and memory efficient.

• It is very fast and works for huge documents.

Disadvantages
• It is event-based so its API is less intuitive.

• Clients never know the full information because the data is broken into pieces.

DOM PARSER SAX PARSER

DOM stands for Document Object Model SAX stands for Simple API for XML

DOM reads the entire document SAX reads node by node

DOM is useful when reading small to medium SAX is used when big files need to b parsed
size XML files

DOM is Tree based parser SAX is Event based parser

DOM is little slow compared to SAX SAX is faster than DOM

//Domparser.html

<html>
<head>
<title>XML DOM Parser</title>
</head>
<body>
<p id="pg"></p>
<script>
var data,parser,xmldoc;
data="<book>"+"<title>Java The Complete Reference</title>"+"<author>Herbert
Schildt</author>"+"<year>2005</year>"+"</book>";
parser = new DOMParser();
xmldoc=parser.parseFromString(data,"text/xml");
document.getElementById("pg").innerHTML=xmldoc.getElementsByTagName("title")[0].childNodes[0
].nodeValue;
</script>
</body>
</html>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 20
Web & Internet technologies UNIT-IV XML, Creating & Using forms

Output:

XML Validation:

A well formed XML document can be validated against DTD or Schema. A well-formed XML
document is an XML document with correct syntax. It is very necessary to know about valid XML
document before knowing XML validation.

A Valid XML Document is a document which must be well formed (Satisfy all the basic syntax
conditions). It should be behave according to predefined DTD or XML schema

Rules for well formed XML

• It must begin with the XML declaration.


• It must have one unique root element.
• All start tags of XML documents must match end tags.
• XML tags are case sensitive.
• All elements must be closed.
• All elements must be properly nested.
• All attributes values must be quoted.
• XML entities must be used for special characters.

XML DTD
A DTD defines the legal elements of an XML document. In simple words we can say that
a DTD defines the document structure with a list of legal elements and attributes. XML schema is
a XML based alternative to DTD. Actually DTD and XML schema both are used to form a well
formed XML document. We should avoid errors in XML documents because they will stop the
XML programs.

XML schema
It is defined as an XML language. Uses namespaces to allow for reuses of existing
definitions. It supports a large number of built in data types and definition of derived data types

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 21
Web & Internet technologies UNIT-IV XML, Creating & Using forms

XSL and XSLT Transformation:

XSL stands for Extensible Stylesheet Language , is a styling language for XML. XSLT stands
for XSL Transformations. XSLT are used to transform XML documents into some other formats like text
or HTML etc.( Like transforming XML into HTML docs). In simple, XSLT is a language for transforming
XML documents.

CSS = Style Sheets for HTML

HTML uses predefined tags. The meaning of, and how to display each tag is well understood. CSS is used
to add styles to HTML elements.

XSL = Style Sheet for XML

XML does not use predefined tags, and therefore the meaning of each tag is not well understood.
A <table> element could indicate an HTML table, a piece of furniture, or something else - and browsers
do not know how to display it. So, XSL describes how the XML elements should be displayed.

Transforming XML Document in to HTML :

<xsl:stylesheet> or <xsl:transform> Element

The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or
<xsl:transform>. <xsl:stylesheet> and <xsl:transform> are completely synonymous and either can be used.

Sytnax :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

or

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template> Element

An XSL style sheet consists of one or more set of rules that are called templates. A template contains rules
to apply when a specified node is matched. The <xsl:template> element is used to build templates. The
match attribute is used to associate a template with an XML element.

<xsl:value-of> Element

The <xsl:value-of> element is used to extract the value of a selected node. The <xsl:value-of> element can
be used to extract the value of an XML element and add it to the output stream of the transformation. The
select attribute contains an XPath expression. An XPath expression works like navigating a file system; a
forward slash (/) selects subdirectories.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 22
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<xsl:for-each> Element

The <xsl:for-each> element allows you to do looping in XSLT. The XSL <xsl:for-each> element can be
used to select every XML element of a specified node-set.

//books.xml

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="booksxsl.xsl"?>

<books>

<book>

<title>Java The Complete Reference</title>

<author>Herbert Schildt</author>

<price>2300</price>

</book>

<book>

<title>Data Structures</title>

<author>Debasis Samanta</author>

<price>1200</price>

</book>

<book>

<title>C Programming</title>

<author>Bala Guru Swamy</author>

<price>1250</price>

</book>

</books>

//booksxsl.xsl

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 23
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<xsl:template match="books">

<html>

<body>

<h2>List of Books</h2>

<table border="1">

<tr>

<th>Title</th>

<th>Author</th>

<th>Price</th>

</tr>

<xsl:for-each select="book">

<tr> <td><xsl:value-of select="title"/></td>

<td><xsl:value-of select="author"/></td>

<td><xsl:value-of select="price"/></td></tr>

</xsl:for-each></table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

Output:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 24
Web & Internet technologies UNIT-IV XML, Creating & Using forms

NewsFeed (RSS and ATOM):

An Atom feed is very similar to an RSS feed in that it is a lightweight XML format allowing
for easy syndication of web content. In fact, most RSS readers and news aggregators will be able
to read Atom feeds just fine, as it is becoming a widely-used alternative to RSS feeds.

What’s a “feed”?

• RSS feed and ATOM feed are small text files that provide information about content on
websites.
• When content is updated, the feed text file is also updated, either manually or
programatically.
• Applications called “readers” or “aggregators” can then check these small text files and
notify someone when new content is available.
• If you already have an RSS feed, creating an Atom feed is extremely easy.

RSS (Really Simple Syndication)

• With RSS it is possible to distribute up-to-date web content from one web site to thousands
of other web sites around the world.
• RSS allows fast browsing for news and updates.
• RSS stands for Really Simple Syndication
//Ex: rssdemo.xml

<?xml version="1.0" encoding="UTF-8" ?>


<rss version="2.0">
<channel>
<title>SVCK Home Page</title>
<link>http://svck.edu.in/</link>

<description>Official; Website of SV College of Engineeing, Kadapa</description> <item>


<title>SVCK CSE Department</title>
<link>http://svck.edu.in/CSE.HTML</link>
<description>Home Page of SVCK CSE Department</description>
</item>
<item>
<title>SVCK ECE Department</title>
<link>http://svck.edu.in/ECE.HTML</link>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 25
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<description>Home Page of SVCK ECE Department</description>


</item>
</channel></rss> Output:

What is ATOM?

• Atom is the name of an XML-based Web content and metadata syndication format, and an
application-level protocol for publishing and editing Web resources belonging to
periodically updated websites.
• All Atom feeds must be well-formed XML documents, and are identified with the
application/atom+xml media type.

<?xml version="1.0" encoding="utf-8"?>


<feed xmlns="http://www.w3.org/2005/Atom">
<title>SVCK Feed</title>

<link href="http://svck.edu.in/"/>
<updated>2020-04-03T18:30:02</updated>
<author>
<name>SVCK</name>
</author>
<entry>
<title>SVCK CSE Department Updates</title>
<link href="http://svck.edu.in/CSE.HTML"/>
<updated>2020-04-03T20:30:02</updated>
<summary>CSE Department Data</summary>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 26
Web & Internet technologies UNIT-IV XML, Creating & Using forms

</entry>
</feed>
Output:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 27
Web & Internet technologies UNIT-IV XML, Creating & Using forms

Creating and Using Forms


Understanding Common Form Issues :

When dealing with forms, we should remember that we are limited to certain variety of fields that
can be applied to a form. These fields are non-negotiable and work in the way they were created
to work. The below tables shows some of the form elements available.
Element Description
TEXT INPUT A simple text box
PASSWORD INPUT A text box that hides the characters inputted
HIDDEN INPUT A field that does not show on the form but can contain data
SELECT A drop-down box with options
LIST A select box that can have multiple options selected
CHECKBOX A box that can be checked
RADIO A radio button that can act as a choice
TEXTAREA A larger box that can contain paragraph-style entries
FILE An element that allows you to browse your computer for a file
SUBMIT A button that will submit the form
RESET A button that will reset the form to its original state
As part of this topic , we need to understand the common issues in below areas.

• GET vs. POST


• Validating form input
• Working with multiple forms

GET Vs POST :

When dealing with forms, you must specify the way that the information entered into the
form is transmitted to its destination (method=""). The two ways available to a web developer are
GET and POST.

When sending data using the GET method, all fields are appended to the Uniform Resource
Locator (URL) of the browser and sent along with the address as data. With the POST method,
values are sent as standard input.

Sending data using the GET method means that fields are generally capped at 150
characters, which is certainly not the most effective means of passing information. It is also not a
secure means of passing data, because many people know how to send information to a script using
an address bar.

Sending data using the POST method is quite a bit more secure (because the method cannot
be altered by appending information to the address bar) and can contain as much information as
you choose to send. Therefore, whenever possible, use the POST method for sending information
and then adjust your script to handle it.

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 28
Web & Internet technologies UNIT-IV XML, Creating & Using forms

PHP 5’s current methods for dealing with GET and POST variables are the $_GET and
$_POST superglobals, respectively. By using these two superglobals, you can designate exactly
where the information should be coming from and subsequently handle the data in the way you
want.

//getform.php
<html>
<head>
<title>PHP GET FORM</title>
</head>
<body>
<form action="getdemo.php" method="get">
Student Name : <input type="text" name="sname"><br><br>
Student Roll No:<input type="text" name="srn"><br><br>
Student Branch :<input type="text" name="sbranch"><br><br>
Student Year :<input type="text" name="syear"><br><br>
<input type="submit" name="submit">
</form>
<?php
?>
</body>
</html>
//getdemo.php

<html>
<head>
<title>PHP GET DEMO</title>
</head>
<body>
<?php
if($_GET)
{
$name=$_GET["sname"];
$rollno=$_GET["srn"];
$branch=$_GET["sbranch"];
$year=$_GET["syear"];
echo "$name bearing roll number $rollno belongs to $year $branch";
}
?>
</body>
</html>
Output:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 29
Web & Internet technologies UNIT-IV XML, Creating & Using forms

//postform.php

<html>
<head>
<title>PHP POST FORM</title>
</head>
<body>
<form action="postdemo.php" method="post">
Student Name : <input type="text" name="sname"><br><br>
Student Roll No:<input type="text" name="srn"><br><br>
Student Branch :<input type="text" name="sbranch"><br><br>
Student Year :<input type="text" name="syear"><br><br>
<input type="submit" name="submit">
</form>
<?php
?>
</body>
</html>
//postdemo.php

<html>
<head>
<title>PHP POST DEMO</title>
</head>
<body>
<?php
if($_POST)
{
$name=$_POST["sname"];
$rollno=$_POST["srn"];
$branch=$_POST["sbranch"];
$year=$_POST["syear"];
echo "$name bearing roll number $rollno belongs to $year $branch";
}
?>
</body>
</html>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 30
Web & Internet technologies UNIT-IV XML, Creating & Using forms

Output:

Validating form input:

In this day and age of constant attacks on websites, one of the biggest issues is attacking
forms directly. To ensure a suitable submission of form data, validation is key. You have many
ways to validate a form and many form elements to consider. Generally, you need to determine
what qualities you want a piece of data to adhere to and then ensure that the submitted data comes
in the correct form. If the data comes in a format that is not to your liking, you must be ready to
take care of this. The following example shows a few examples of form validation using PHP.

Validation is a way to catch mistakes when they happen (or even better, to prevent them from
happening at all).

Client-side validation: These are the checks that happen in the browser, before a form is
submitted. The goal here is to make life easier for the people filling out the form.

Examples: HTML5, JavaScript etc.

Server-side validation: These are the checks that happen after a form is sent back to the web
server. At this point, it is up to your server-side code to review the details and make sure everything
is proper before continuing. No matter what the browser does, server-side validation is essential.

The following example shows a few examples of form validation using PHP.

//validation.php

<html>
<head>
<title>PHP Form Validation</title>
</head>
<body>
<form action="<?php echo $_SERVER["PHP_SELF"] ?>" method="post">
User Name : <input type="text" name="uname">
Password : <input type="password" name="pwd">
<input type="submit" name="submit">
</form>
<?php

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 31
Web & Internet technologies UNIT-IV XML, Creating & Using forms

if($_POST)
{
$name=$_POST["uname"];
$pswd=$_POST["pwd"];
if($name==""||$pswd=="")
{
echo "<font color='red'>Username or Password should not be empty</font>";
}
else if(strlen($name)<6)
{
echo "<font color='red'>Username should not contain less than 6 characters</font>";
}
else if(strlen($pswd)<6)
{
echo "<font color='red'>Password should not contain less than 6 characters</font>";
}
if($name!="" && $pswd!="" && strlen($name)>=6 && strlen($pswd)>=6)
{
echo " Welcome User $name<br><br>";
echo " Your password is $pswd";
}
}

?>
</body>
</html>
Output:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 32
Web & Internet technologies UNIT-IV XML, Creating & Using forms

In the above script: $_SERVER[“PHP_SELF"] The filename of the currently executing


script, relative to the document root. The above program demonstrates the validation in same page.
It is possible to perform the validations using GET and POST methods into the other pages.

Working with multiple forms:

Sometimes you will need to collect values from more than one page. Most developers do
this for the sake of clarity. By providing forms on more than one page, you can separate blocks of
information and thus create a flexible experience for the user. The problem, therefore, is how to
GET values from each page onto the next page and finally to the processing script.

Being the great developer that you are, you can solve this problem and use the hidden input form
type. When each page loads, you only load the values from the previous pages into hidden form
elements and submit them.

//pag1.php

<html>
<head>
<title>Personal Information</title>
</head>
<body>
<form action="pag2.php" method="post">
First Name : <input type="text" name="fname" required><br><br>
Last Name : <input type="text" name="lname"><br><br>
Father Name : <input type="text" name="faname"><br><br>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 33
Web & Internet technologies UNIT-IV XML, Creating & Using forms

Gender:
<input type="radio" name="gen" value="male" checked>Male
<input type="radio" name="gen" value="female">Female<br><br>
Email id : <input type="email" name="email"><br><br>
Mobile Number : <select name="mbn">
<option value="+91">+91</option>
<option value="+92" selected>+92</option>
<option value="+93">+93</option>
</select>
<input type="number" name="nmb"><br><br>
Area of interest :
<input type="checkbox" name="aoi" value="Networking" checked>Networking
<input type="checkbox" name="aoi" value="Data Mining">Data Mining
<input type="checkbox" name="aoi" value="Cloud Computing">Cloud Computing<br><br>
Photo : <input type="file" name="pic"><br><br>
<input type="Reset" value="CLEAR">
<input type="submit" value="NEXT">
</form>
</body>
<?php
?>
</html>
//pag2.php

<html>
<head>
<title>Contact Information</title>
</head>
<body>
<form action="pag3.php" method="post">
D.No : <input type="text" name="dno"><br><br>
Street Name : <input type="text" name="stname"><br><br>
Address Line1 : <input type="text" name="adr1"><br><br>
Address Line2 : <input type="text" name="adr2"><br><br>
Town / Village : <input type="text" name="twn"><br><br>
District : <select name="dst">
<option>YSR Kadapa</option>
<option>Chittoor</option>
<option>Anantapur</option>
<option>Kurnool</option>
</select> <br><br>
State : <select name="st">
<option>Andhra Pradesh</option>
<option>Telangana</option>
</select><br><br>
<input type="Reset" value="CLEAR">
<input type="submit" value="NEXT">

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 34
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<input type="hidden" name="fname" value="<?php echo $_POST['fname']?>"><br>


<input type="hidden" name="lname" value="<?php echo $_POST['lname']?>"><br>
<input type="hidden" name="faname" value="<?php echo $_POST['faname']?>"><br>
<input type="hidden" name="gen" value="<?php echo $_POST['gen']?>"><br>
<input type="hidden" name="email" value="<?php echo $_POST['email']?>"><br>
<input type="hidden" name="mbn" value="<?php echo $_POST['mbn']?>"><br>
<input type="hidden" name="nmb" value="<?php echo $_POST['nmb']?>"><br>
<input type="hidden" name="aoi" value="<?php echo $_POST['aoi']?>"><br>
<input type="hidden" name="pic" value="<?php echo $_POST['pic']?>"><br>
</form>
</body>
<?php
?>
</html>
//pag3.php

<html>
<head>
<title>Educational Information</title>
</head>
<body>
<form action="pag4.php" method="post">
SSC Roll.No : <input type="text" name="sscrn"><br><br>
SSC Year of Passing<select name="sscyop">
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
</select><br><br>
SSC Percentage : <input type="text" name="sscpc"><br><br>
Intermediate Roll.No : <input type="text" name="irn"><br><br>
Intermediate Year of Passing<select name="iyop">
<option>2005</option>
<option>2006</option>
<option>2007</option>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 35
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
</select><br><br>
Intermediate Percentage : <input type="text" name="ipc"><br><br>
UG Roll.No : <input type="text" name="urn"><br><br>
UG Year of Passing<select name="uyop">
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
</select><br><br>
UG Percentage : <input type="text" name="upc"><br><br>
<input type="Reset" value="CLEAR">
<input type="submit" value="SUBMIT">
<input type="hidden" name="fname" value="<?php echo $_POST['fname']?>"><br>
<input type="hidden" name="lname" value="<?php echo $_POST['lname']?>"><br>
<input type="hidden" name="faname" value="<?php echo $_POST['faname']?>"><br>
<input type="hidden" name="gen" value="<?php echo $_POST['gen']?>"><br>
<input type="hidden" name="email" value="<?php echo $_POST['email']?>"><br>
<input type="hidden" name="mbn" value="<?php echo $_POST['mbn']?>"><br>
<input type="hidden" name="nmb" value="<?php echo $_POST['nmb']?>"><br>
<input type="hidden" name="aoi" value="<?php echo $_POST['aoi']?>"><br>
<input type="hidden" name="pic" value="<?php echo $_POST['pic']?>"><br>

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 36
Web & Internet technologies UNIT-IV XML, Creating & Using forms

<input type="hidden" name="dno" value="<?php echo $_POST['dno']?>"><br>


<input type="hidden" name="stname" value="<?php echo $_POST['stname']?>"><br>
<input type="hidden" name="adr1" value="<?php echo $_POST['adr1']?>"><br>
<input type="hidden" name="adr2" value="<?php echo $_POST['adr2']?>"><br>
<input type="hidden" name="twn" value="<?php echo $_POST['twn']?>"><br>
<input type="hidden" name="dst" value="<?php echo $_POST['dst']?>"><br>
<input type="hidden" name="st" value="<?php echo $_POST['st']?>"><br>
</form>
</body>
<?php
?>
</html>
//pag4.php

<html>
<head>
<title>Candidate Information</title>
</head>
<body>
<?php
echo "Personal Information <br><br>";
echo "-----------------------------<br><br>";
echo "First Name :", $_POST['fname'],"<br><br>";
echo "Last Name :",$_POST['lname'],"<br><br>";
echo "Father Name : ",$_POST['faname'],"<br><br>";
echo "Gender : ",$_POST['gen'],"<br><br> ";
echo "Email : ",$_POST['email'],"<br><br> ";
echo "Mobile Number : ",$_POST['mbn'],$_POST['nmb'],"<br><br> ";
echo "Area of Interest : ",$_POST['aoi'],"<br><br> ";
echo "Photo : ",$_POST['pic'],"<br><br> ";
echo "-----------------------------<br><br>";
echo "Contact Information <br><br>";
echo "-----------------------------<br><br>";
echo "Door No:",$_POST['dno'],"<br><br>";
echo "Street Name : ",$_POST['stname'],"<br><br>";
echo "Address Line 1 : ",$_POST['adr1'],"<br><br>";
echo "Address Line 2 : ",$_POST['adr2'],"<br><br>";
echo "Town/village: ",$_POST['twn'],"<br><br>";
echo "District : ",$_POST['dst'],"<br><br>";
echo "Street Name : ",$_POST['st'],"<br><br>";
echo "-----------------------------<br><br>";
echo "Educational Information <br><br>";
echo "-----------------------------<br><br>";
echo "SSC Roll.No : ",$_POST['sscrn'],"<br><br>";
echo "SSC Year of Passing : ",$_POST['sscyop'],"<br><br>";
echo "SSC Percentage : ",$_POST['sscpc'],"<br><br>";
echo "Intermediate Roll.No : ",$_POST['irn'],"<br><br>";

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 37
Web & Internet technologies UNIT-IV XML, Creating & Using forms

echo "Intermediate Year of Passing : ",$_POST['iyop'],"<br><br>";


echo "Intermediate Percentage : ",$_POST['ipc'],"<br><br>";
echo "UG Roll.No : ",$_POST['urn'],"<br><br>";
echo "UG Year of Passing : ",$_POST['uyop'],"<br><br>";
echo "UG Percentage : ",$_POST['upc'],"<br><br>";
echo "-----------------------------<br><br>";
?></body></html> pag1.php pag2.php

pag3.php pag4.php

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 38
Web & Internet technologies UNIT-IV XML, Creating & Using forms

Preventing Multiple Submissions of a form:


One possible occurrence that happens often is that users become impatient when waiting for your script to
do what it is doing, and hence they click the submit button on a form repeatedly. This can create confusion to your
script because, while the user may not see anything happening, your script is probably going ahead with whatever it
has been programmed to do.

Of particular danger are credit card number submittals. If a user continually hits the submit button on a credit
card submittal form, their card may be charged multiple times if the developer has not taken the time to validate against
such an eventuality. You can deal with multiple submittal validation in essentially two ways.

• Server side refers to a script located on the server that is receiving the data.

• Client side is mostly browser related.

When we browse some popular websites and submits a form we don’t know whether it is processed or not and
we click submit button again and again hence same request goes to server more than one time.

This results in unpredictable behaviour which only complicates user experience. Avoiding multiple submission
of HTML form is common requirement in Web Applications using Servlet, JSP and any other web technology. One
of the simple solutions is to disable submit button inside HTML and JavaScript instead on server side.

//testsub.php
<html>
<head>
<title>Test Sub</title>
</head>
<body>
<form action="" method="post">
User Name : <input type="text" name="uname"><br><br>
Password : <input type="password" name="pwd"><br><br>
<input type="submit" name="SUBMIT" value="SubmitWAIT" onclick="this.value='Submitting
..';this.disabled='disabled'; this.form.submit();" />
<input type="submit" name="SUBMIT" value="SubmitDISABLE" onclick="this.disabled='disabled'" />
</form>
<?php
?>
</body>
</html>

Output:

Prepared by P.M. Fayaz Ahmed, Asst. Prof, CSE, SVCE, Kadapa Page 39

You might also like