0% found this document useful (0 votes)
39 views9 pages

HTMLForms

HTML forms allow users to input data on a website. The data is then sent to a server-side script for processing. Forms consist of elements like input fields, labels, and buttons. The <form> element defines the form, the <input> element creates input fields, and the <button> element creates submit buttons. Forms can use the GET method, which appends data to the URL, or the POST method, which sends data in the request body.

Uploaded by

alaa abu madi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views9 pages

HTMLForms

HTML forms allow users to input data on a website. The data is then sent to a server-side script for processing. Forms consist of elements like input fields, labels, and buttons. The <form> element defines the form, the <input> element creates input fields, and the <button> element creates submit buttons. Forms can use the GET method, which appends data to the URL, or the POST method, which sends data in the request body.

Uploaded by

alaa abu madi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

HTML Forms

HTML Forms
• HTML forms are used to collect information from users on a website.
• They allow users to input data, which can be processed by a server-
side script.
• HTML forms consist of various elements, including input fields,
labels, and buttons.
HTML Forms Elements
<form> element: Defines a form that collects user input.
Attributes:
1. action: specifies where to send the form data when submitted
2. method: specifies the HTTP method to use when sending the form data (GET or POST)
<input> element: Creates an input field for the user to enter data.
Attributes:
3. type: specifies the type of input field (text, password, checkbox, radio, email, etc.)
4. name: specifies the name of the input field
5. value: specifies the default value of the input field
6. placeholder: specifies a short hint that describes the expected value of the input field
7. required: specifies that the input field must be filled out before submitting the form
8. readonly: specifies that the input field cannot be modified by the user
9. disabled: specifies that the input field is disabled and cannot be used
10.size: specifies the visible width of the input field
11.maxlength: specifies the maximum length of the input field
12.min and max: specifies the minimum and maximum values for a number input field
HTML Forms Elements
<button> element: Creates a button that can be clicked by the user to
submit the form or perform some other action.
Attributes:
1. type: specifies the type of button (submit, reset, or button)
2. name: specifies the name of the button
3. value: specifies the value of the button
• Other Form elements:
• <textarea>
• <select>
• <label>
Example: The Form
• Suppose this form is accessed by
controller’s action ‘add_user_form’
and it’s rendered by view
’add_user_form.html’
• To access this form, if it’s defined in
default.py controller, would be:
/default/add_user_form
• This Form submits data collected in
input text name and input text email to
to the current controller action
‘add_user’
Example: The Form
• The ’add_user’ action can access
the submitted data using web2py
request object
• The request object stores the
submitted data as collection of key-
value pairs in a dictionary called
‘vars’
• So, to access the submitted name
value:
name= request.vars[‘name’]
GET and POST methods
• The difference between the POST and GET methods in HTML forms
lies in how the data submitted in the form is transmitted to the server.
• The default method used by the HTML form is GET
• It can be changed using the form’s attribute method
GET and POST methods
GET method:
• Submits the form data as part of the URL in the form of query
parameters.
• The data is visible in the URL, which means it can be bookmarked,
cached, or shared with others.
• It's typically used when retrieving data from the server (e.g.,
searching, filtering, or sorting data).
• There are limits on the amount of data that can be sent using the GET
method, typically around 2048 characters.
GET and POST methods
POST method:
• Submits the form data in the request body as a separate message.
• The data is not visible in the URL and can't be bookmarked, cached, or
shared with others.
• It's typically used when sending data to the server (e.g., creating,
updating, or deleting data).
• There are no limits on the amount of data that can be sent using the
POST method.

You might also like