HTML form Attributes

HTML form Attributes

The <form> element in HTML can include several attributes to control how form data is submitted, processed, and displayed. These attributes define the behavior and functionality of the form.


Common Form Attributes

Attribute Description Example
action URL of the server-side script to process the form <form action="submit.php">
method HTTP method to send data: GET or POST <form method="post">
enctype Encoding type for form data (needed for file uploads) <form enctype="multipart/form-data">
name Name of the form (used in scripts) <form name="contactForm">
id Unique identifier for the form (CSS/JS) <form id="regForm">
target Where to display the response (_self, _blank, _parent, _top) <form target="_blank">
autocomplete Enable or disable autofill for form fields <form autocomplete="off">
novalidate Disables HTML5 form validation <form novalidate>
accept-charset Character encodings the server accepts <form accept-charset="UTF-8">

Example HTML Form Using Form Attributes


 


Explanation

  • action="submit.php" → Sends form data to submit.php.

  • method="post" → Uses POST method to send data securely.

  • enctype="multipart/form-data" → Required for file uploads.

  • id & name → Unique identifiers for scripting or CSS.

  • autocomplete="on" → Browser can auto-fill previously entered values.


Key Points

  • Always include action and method for proper form submission.

  • Use enctype="multipart/form-data" when handling file uploads.

  • novalidate disables browser-side validation if you plan to validate manually.

  • accept-charset ensures correct character encoding for multilingual forms.

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *