0% found this document useful (0 votes)
0 views

web programming lecture 2

The document provides an overview of HTML forms, detailing their purpose for collecting user input and the various elements involved, such as <form>, <input>, <textarea>, and <select>. It explains attributes like action, method, and target, as well as the differences between GET and POST methods for form submission. Additionally, it highlights the importance of the name attribute for input fields and introduces various input types available in HTML.

Uploaded by

ihhridoy000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

web programming lecture 2

The document provides an overview of HTML forms, detailing their purpose for collecting user input and the various elements involved, such as <form>, <input>, <textarea>, and <select>. It explains attributes like action, method, and target, as well as the differences between GET and POST methods for form submission. Additionally, it highlights the importance of the name attribute for input fields and introduces various input types available in HTML.

Uploaded by

ihhridoy000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Lecture on HTML Forms

Prepared By Dr. Tushar Kanti Saha

HTML Forms
An HTML form is used to collect user input. The user input can then be
sent to a server for processing.

Example
First name:
John

Last name:
Doe

Submit

The <form> Element


The HTML <form> element is used to create an HTML form for user input:
<form>
.
form elements
.
</form>

List of All <form> Attributes


Attribute Description

accept-charset Specifies the character encodings used for form submission

action Specifies where to send the form-data when a form is submitted

autocomplete Specifies whether a form should have autocomplete on or off

enctype Specifies how the form-data should be encoded when submitting it to the server
(only for method="post")

method Specifies the HTTP method to use when sending form-data

name Specifies the name of the form

novalidate Specifies that the form should not be validated when submitted

rel Specifies the relationship between a linked resource and the current document

target Specifies where to display the response that is received after submitting the form
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

The <input> Element


The <input> element is the most important form element.
An <input> element can be displayed in many ways, depending on
the type attribute.
Here are some examples:

Type Description

<input type="text"> Displays a single-line text input field

<input type="radio"> Displays a radio button (for selecting one of many


choices)

<input type="submit"> Displays a submit button (for submitting the form)

Text Fields
<input type="text"> defines a single-line input field for text input.

Example
A form with two text input fields:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>

This is how it will look like in a browser:

First name:

Last name:
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Radio Buttons
<input type="radio"> defines a radio button.

Radio buttons let a user select ONE of a limited number of choices.

Example
A form with radio buttons:

<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
</form>

This is how the HTML code above will be displayed in a browser:

Male
Female
Other

The Submit Button


1. <input type="submit"> defines a button for submitting the form data to
a form-handler.
2. The form-handler is typically a page on the server with a script for
processing input data.
3. The form-handler is specified in the form's action attribute.

Example
A form with a submit button:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
This is how the HTML code above will be displayed in a browser:

First name:
John

Last name:
Doe

Submit

The Action Attribute


 The action attribute defines the action to be performed when the form is
submitted.
 Usually, the form data is sent to a page on the server when the user clicks
on the submit button.
 In the example above, the form data is sent to a page on the server called
"/action_page.php". This page contains a server-side script that handles
the form data:
<form action="/action_page.php">

If the action attribute is omitted, the action is set to the current page.

The Target Attribute


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
Here, the submitted result will open in a new browser tab:
<form action="/action_page.php" target="_blank">

Other legal values are "_parent", "_top", or a name representing the name of
an iframe.
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

The Method Attribute


The method attribute specifies the HTTP method (GET or POST) to be used
when submitting the form data.

Example
Use the GET method when submitting the form:
<form action="/action_page.php" method="get">

or:

Example
Use the POST method when submitting the form:

<form action="/action_page.php" method="post">

When to Use GET?


The default HTTP method when submitting form data is GET.

However, when GET is used, the form data will be visible in the page's
address field:

/action_page.php?firstname=John&lastname=Doe

Notes on GET:

 Appends form-data into the URL in name/value pairs


 The length of a URL is limited (2048 characters)
 Never use GET to send sensitive data! (will be visible in the URL)
 Useful for form submissions where a user wants to bookmark the
result
 GET is better for non-secure data, like query strings in Google

When to Use POST?


Always use POST if the form data contains sensitive or personal information.
The POST method does not display the form data in the page address field.

Notes on POST:

 POST has no size limitations, and can be used to send large amounts
of data.
 Form submissions with POST cannot be bookmarked
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

The Name Attribute


Each input field must have a name attribute to be submitted.

If the name attribute is omitted, the data of that input field will not be sent at
all.

Example
This example will not submit the value of the "First name" input field:

<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" value="John"><br><br>
<input type="submit" value="Submit">
</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

<output> Defines the result of a calculation


Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

The <input> Element


One of the most used form element is the <input> element.
The <input> element can be displayed in several ways, depending on
the type attribute.

Example
A form with a submit button:
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>

This is how the HTML code above will be displayed in a browser:

First name:
John

Last name:
Doe

Submit

Note: If the type attribute is omitted, the input field gets the default type:
"text".

All the different input types are covered in the next chapter: HTML Input
Types.

The <label> Element


 The <label> tag defines a label for many form elements.
 The <label> element is useful for screen-reader users, because the screen-
reader will read out loud the label when the user is focused on the input
element.
 The <label> element also help users who have difficulty clicking on very
small regions (such as radio buttons or checkboxes) - because when the
user clicks the text within the <label> element, it toggles the radio
button/checkbox.
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
 The for attribute of the <label> tag should be equal to the id attribute of
the <input> element to bind them together.

Note: The use of the <label> element in the example above.

The <select> Element


The <select> element defines a drop-down list:

Example
<label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

The <option> elements defines an option that can be selected.


By default, the first item in the drop-down list is selected.
To define a pre-selected option, add the selected attribute to the option:

Example
<option value="fiat" selected>Fiat</option>

Visible Values:
Use the size attribute to specify the number of visible values:

Example
<label for="cars">Choose a car:</label>
<select id="cars" 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>

Allow Multiple Selections:


Use the multiple attribute to allow the user to select more than one value:
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Example
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" size="4" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

The <textarea> Element


The <textarea> element defines a multi-line input field (a text area):

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.
This is how the HTML code above will be displayed in a browser:

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>

The <button> Element


The <button> element defines a clickable button:
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Example
<button type="button" onclick="alert('Hello World!')">Click
Me!</button>

This is how the HTML code above will be displayed in a browser:

Note: Always specify the type attribute for the button element. Different
browsers may use different default types for the button element.

The <fieldset> and <legend> Elements


The <fieldset> element is used to group related data in a form.
The <legend> element defines a caption for the <fieldset> element.

Example
<form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>

This is how the HTML code above will be displayed in a browser:

Personalia:First name:
John

Last name:
Doe

Submit

The <datalist> Element


The <datalist> element specifies a list of pre-defined options for
an <input> element.
Users will see a drop-down list of the pre-defined options as they input data.
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
The list attribute of the <input> element, must refer to the id attribute of
the <datalist> element.

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>

The <output> Element


The <output> element represents the result of a calculation (like one
performed by a script).

Example
Perform a calculation and show the result in an <output> element:
<form action="/action_page.php" oninput="x.value=parseInt(a.value)+pars
eInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

HTML Input Types


Here are the different input types you can use in HTML:

 <input type="button">
 <input type="checkbox">
 <input type="color">
 <input type="date">
 <input type="datetime-local">
 <input type="email">
 <input type="file">
 <input type="hidden">
 <input type="image">
 <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">
 <input type="week">

Input Type Text


<input type="text"> defines a single-line text input field:

Example
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>

This is how the HTML code above will be displayed in a browser:

First name:

Last name:
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Input Type Password


<input type="password"> defines a password field:

Example
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>

This is how the HTML code above will be displayed in a browser:

Username:

Password:

The characters in a password field are masked (shown as asterisks or


circles).

Input Type Submit


<input type="submit"> defines a button for submitting 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">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>

This is how the HTML code above will be displayed in a browser:


Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
First name:
John

Last name:
Doe

Submit

If you omit the submit button's value attribute, the button will get a default
text:

Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit">
</form>

Input Type Reset


<input type="reset"> defines a reset button that will reset all form values to
their default values:

Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>

This is how the HTML code above will be displayed in a browser:

First name:
John

Last name:
Doe
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Submit Reset

If you change the input values and then click the "Reset" button, the form-
data will be reset to the default values.

Input Type Radio


<input type="radio"> defines a radio button.

Radio buttons let a user select ONLY ONE of a limited number of choices:

Example
<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
</form>

This is how the HTML code above will be displayed in a browser:

Male
Female
Other

Input Type Checkbox


<input type="checkbox"> defines a checkbox.

Checkboxes let a user select ZERO or MORE options of a limited number of


choices.

Example
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>

This is how the HTML code above will be displayed in a browser:

I have a bike
I have a car
I have a boat

Input Type Button


<input type="button"> defines a button:

Example
<input type="button" onclick="alert('Hello World!')" value="Click Me!">

This is how the HTML code above will be displayed in a browser:

Input Type Color


The <input type="color"> is used for input fields that should contain a color.

Depending on browser support, a color picker can show up in the input field.

Example
<form>
<label for="favcolor">Select your favorite color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>

Input Type Date


The <input type="date"> is used for input fields that should contain a date.
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
Depending on browser support, a date picker can show up in the input field.

Example
<form>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
</form>

You can also use the min and max attributes to add restrictions to dates:

Example
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-
31"><br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-02">
</form>

Input Type Datetime-local


The <input type="datetime-local"> specifies a date and time input field, with no
time zone.
Depending on browser support, a date picker can show up in the input field.

Example
<form>
<label for="birthdaytime">Birthday (date and time):</label>
<input type="datetime-local" id="birthdaytime" name="birthdaytime">
</form>

Input Type Email


1. The <input type="email"> is used for input fields that should contain an e-
mail address.
2. Depending on browser support, the e-mail address can be automatically
validated when submitted.
3. Some smartphones recognize the email type, and add ".com" to the
keyboard to match email input.
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Example
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>

Input Type File


The <input type="file"> defines a file-select field and a "Browse" button for file
uploads.

Example
<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>

Input Type Month


The <input type="month"> allows the user to select a month and year.
Depending on browser support, a date picker can show up in the input field.

Example
<form>
<label for="bdaymonth">Birthday (month and year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>

Input Type Number


The <input type="number"> defines a numeric input field.
You can also set restrictions on what numbers are accepted.
The following example displays a numeric input field, where you can enter a
value from 1 to 5:

Example
<form>
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Input Restrictions
Here is a list of some common 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

You will learn more about input restrictions in the next chapter.

The following example displays a numeric input field, where you can enter a
value from 0 to 100, in steps of 10. The default value is 30:

Example
<form>
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" min="0" max="100"
step="10" value="30">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Input Type Range


The <input type="range"> defines a control for entering a number whose exact
value is not important (like a slider control). Default range is 0 to 100.
However, you can set restrictions on what numbers are accepted with
the min, max, and step attributes:

Example
<form>
<label for="vol">Volume (between 0 and 50):</label>
<input type="range" id="vol" name="vol" min="0" max="50">
</form>

Input Type Search


The <input type="search"> is used for search fields (a search field behaves like
a regular text field).

Example
<form>
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
</form>

Input Type Tel


The <input type="tel"> is used for input fields that should contain a telephone
number.

Example
<form>
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-
[0-9]{3}">
</form>

Input Type Time


The <input type="time"> allows the user to select a time (no time zone).

Depending on browser support, a time picker can show up in the input field.
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

Example
<form>
<label for="appt">Select a time:</label>
<input type="time" id="appt" name="appt">
</form>

Input Type Url


1. The <input type="url"> is used for input fields that should contain a URL
address.
2. Depending on browser support, the url field can be automatically
validated when submitted.
3. Some smartphones recognize the url type, and adds ".com" to the
keyboard to match url input.

Example
<form>
<label for="homepage">Add your homepage:</label>
<input type="url" id="homepage" name="homepage">
</form>

Input Type Week


1. The <input type="week"> allows the user to select a week and year.
2. Depending on browser support, a date picker can show up in the input
field.

Example
<form>
<label for="week">Select a week:</label>
<input type="week" id="week" name="week">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

HTML Input form* Attributes


This chapter describes the different form* attributes for the
HTML <input> element.

1. form Attribute
The input form attribute specifies the form the <input> element belongs to.
The value of this attribute must be equal to the id attribute of the <form>
element it belongs to.

Example
An input field located outside of the HTML form (but still a part of the form):
<form action="/action_page.php" id="form1">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
</form>

<label for="lname">Last name:</label>


<input type="text" id="lname" name="lname" form="form1">

2. formaction Attribute
The input formaction attribute specifies the URL of the file that will process the
input when the form is submitted.
Note: This attribute overrides the action attribute of the <form> element.
The formaction attribute works with the following input types: submit and
image.

Example
An HTML form with two submit buttons, with different actions:
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formaction="/action_page2.php" value="Submit as
Admin">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

3. formenctype Attribute
The input formenctype attribute specifies how the form-data should be encoded
when submitted (only for forms with method="post").

Note: This attribute overrides the enctype attribute of the <form> element.

The formenctype attribute works with the following input types: submit and
image.

Example
A form with two submit buttons. The first sends the form-data with default
encoding, the second sends the form-data encoded as "multipart/form-data":
<form action="/action_page_binary.asp" method="post">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formenctype="multipart/form-data"
value="Submit as Multipart/form-data">
</form>

4. formmethod Attribute
 The input formmethod attribute defines the HTTP method for sending form-
data to the action URL.
 The formmethod attribute works with the following input types: submit and
image.
 The form-data can be sent as URL variables (method="get") or as an
HTTP post transaction (method="post").

Note: This attribute overrides the method attribute of the <form> element.

Notes on the "get" method:

 This method appends the form-data to the URL in name/value pairs


 This method is useful for form submissions where a user want to
bookmark the result
 There is a limit to how much data you can place in a URL (varies
between browsers), therefore, you cannot be sure that all of the form-
data will be correctly transferred
 Never use the "get" method to pass sensitive information! (password
or other sensitive information will be visible in the browser's address
bar)
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha
Notes on the "post" method:

 This method sends the form-data as an HTTP post transaction


 Form submissions with the "post" method cannot be bookmarked
 The "post" method is more robust and secure than "get", and "post"
does not have size limitations

Example
A form with two submit buttons. The first sends the form-data with
method="get". The second sends the form-data with method="post":
<form action="/action_page.php" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit using GET">
<input type="submit" formmethod="post" value="Submit using POST">
</form>

4. formtarget Attribute
The input formtarget a attribute specifies a name or a keyword that indicates
where to display the response that is received after submitting the form.

Note: This attribute overrides the target attribute of the <form> element.

The formtarget attribute works with the following input types: submit and
image.

Example
A form with two submit buttons, with different target windows:
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="Submit">
<input type="submit" formtarget="_blank" value="Submit to a new
window/tab">
</form>
Lecture on HTML Forms
Prepared By Dr. Tushar Kanti Saha

5. formnovalidate Attribute
The input formnovalidate attribute specifies that an <input> element should
not be validated when submitted.
Note: This attribute overrides the novalidate attribute of the <form> element.
The formnovalidate attribute works with the following input types: submit.

Example
A form with two submit buttons (with and without validation):
<form action="/action_page.php">
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
<input type="submit" formnovalidate="formnovalidate"
value="Submit without validation">
</form>

6. novalidate Attribute
1. The novalidate attribute is a <form> attribute.
2. When present, novalidate specifies that all of the form-data should not be
validated when submitted.

Example
Specify that no form-data should be validated on submit:
<form action="/action_page.php" novalidate>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>

You might also like