HTML Form Attributes

HTML Form Attributes <form> tag के attributes होते हैं जो यह control करते हैं कि form का data कहाँ, कैसे और किस तरीके से submit होगा।
ये attributes form के behavior को define करते हैं।

action Attribute

action attribute यह बताता है कि form submit होने पर data किस URL पर भेजा जाएगा।

<form action="submit.php">

अगर action empty छोड़ा जाए, तो form current page पर ही submit होता है।

method Attribute

method attribute data भेजने का तरीका बताता है।

<form method="get">
<form method="post">

GET method
Data URL में दिखाई देता है
Search और non-sensitive data के लिए use होता है

POST method
Data URL में दिखाई नहीं देता
Login और sensitive data के लिए use होता है

target Attribute

target attribute यह decide करता है कि response कहाँ open होगा।

<form action="submit.php" target="_blank">

Common values
_self (default)
_blank
_parent
_top

enctype Attribute

enctype attribute data encoding type define करता है।

<form method="post" enctype="multipart/form-data">

Common enctype values
application/x-www-form-urlencoded (default)
multipart/form-data (file upload के लिए)
text/plain (testing purpose)

autocomplete Attribute

autocomplete browser को बताता है कि previous values suggest करनी हैं या नहीं।

<form autocomplete="on">
<form autocomplete="off">

Sensitive forms में autocomplete off किया जाता है।

novalidate Attribute

novalidate attribute browser की built-in validation को disable करता है।

<form novalidate>

यह तब useful होता है जब custom validation use की जा रही हो।

name Attribute

name attribute form को uniquely identify करता है।

<form name="loginForm">

JavaScript में form access करने के लिए use होता है।

accept-charset Attribute

accept-charset attribute define करता है कि form data किस character encoding में भेजा जाएगा।

<form accept-charset="UTF-8">

Multi-language forms के लिए UTF-8 best choice है।

rel Attribute

rel attribute form submission के relation को define करता है।

<form rel="noopener">

यह mostly security-related cases में use होता है।

form Attribute का Real Example

<form
  action="register.php"
  method="post"
  target="_self"
  enctype="multipart/form-data"
  autocomplete="off"
  accept-charset="UTF-8">
  
  <label>Username</label>
  <input type="text" required>

  <label>Password</label>
  <input type="password" required>

  <button type="submit">Register</button>
</form>

Form Attributes और Security

Sensitive data के लिए POST method use करें
File upload के लिए सही enctype ज़रूरी है
HTTPS के साथ forms use करें
Autocomplete carefully handle करें

HTML Form Attributes Summary

Form attributes submission behavior control करते हैं
action और method सबसे important attributes हैं
enctype file upload के लिए ज़रूरी है
autocomplete और novalidate form experience control करते हैं
UTF-8 encoding recommended है।

Share your love