Forms provide way to collect user data. I think you also fill the form in your life
manually or online.In manual form it can be printed document or hand written
form. Have you not come to your mind the question of how to display that form
on the web page and how to generate that form? I had that problem. I found
the answer of that problem. Now I am solving your problem.
Form also created using HTML. Let's learn how to create the form using HTML.
What the form?
HTML Form tags
- <form>--</form>
Form elements have different types of input elements. Input elements of
form will discuss in next blog.
Attributes of the Form
- action="url" (required)
Specifies where to send the data when the Submit button is clicked.
<form action="/action_page.php">--</form>
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>--</form> OR <form action="#">--</form>
If the action attribute is ommitted, the action is set the current page.
- method="get"
Form data is sent as a URL with ? form_data info appended to the end.
The submitted form data will be visible in the page address field.
/action_page.php?firstname=Mickey&lastname=Mouse
The default method when submitting form data is GET.
<form action="/action_page.php" method="get">
NOTE : 1. That method not good for the users. Because if some user
submit his/her private data like credit card number, passwords.
and leave with out closing the tab. Some people went to that
computer and he/she can see the data of the user. It is threat to
that person's life. Therefore the get method not good for the
form submission.
2. GET is better for non-secure data, like query string in Google.
3. Can be used only if data is all ASCII and not more that 100
characters.
- method="post"
Form data is sent to the body of the URL request. The POST method
does not display the submitted form data in the page address field.
<form action="/action_page.php" method="post">
NOTE : 1. POST has no size limitations, and can be used to send large
amounts of data.
2. Form submissions with POST cannot be bookmarked.
- target="target"
Tell where to open the page sent as a result of the request.
target=_blank : means open in a new window.
target=_top : means use the same window.
- name="form1" : It is required attribute in form. Specifies a name used to identify the form.
- accept-charset : Specifies the charset used in the submitted form (default: the page charset).
- autocomplete : Specifies if the browser should autocomplete the form (default: on).
- enctype : Specifies the encoding of the submitted data (default: is url-encoded).
- novalidate : Specifies that the browser should not validate the form.
Did you see some form group their information like personal information, contact
information?
This is the example for the grouping of the form. I think you get that.
Let's see how to grouping the form in HTML.
- <fieldset> : used to group related data in a form.
- <legend> : defines a caption for the <fieldset> element.
Example code
<form action="/action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Output :
I think now you have a basic idea about the form.
See you soon with the HTML Form Part 2 (input element).
No comments:
Post a Comment