DAY 5 – FORMS PART 2
1. action Attribute:
- The `action` attribute specifies the URL where the form data should be sent when the user
submits the form.
- It defines the server-side script or endpoint responsible for processing the form data.
Example:
<form action="submit.php" method="post">
<!-- Form elements go here -->
</form>
2. method Attribute (GET and POST):
- The `method` attribute specifies how the form data should be sent to the server. It can have two
values: "get" or "post."
- "GET" appends form data to the URL, making it visible in the address bar.
- "POST" sends form data in the HTTP request body, keeping it hidden.
Example:
<form action="submit.php" method="get">
<!-- Form elements go here -->
</form>
3. name` Attribute in `<input>` Element:
- The `name` attribute assigns a name to an input element. It's used to identify and reference the
input data when the form is submitted.
- The name is crucial for server-side processing to access the submitted data.
Example:
<input type="text" name="username">
4. placeholder Attribute:
- The `placeholder` attribute provides a hint or example text inside an input field to guide users on
what to enter.
- It is displayed as grayed-out text and disappears when the user starts typing.
Example:
<input type="email" name="user_email" placeholder="Enter your email">
5. value` Attribute:
- The `value` attribute sets an initial value for an input element.
- It can be used to prepopulate input fields with default or saved data.
Example:
<input type="text" name="first_name" value="John">
6. maxlength` and `minlength` Attributes:
- `maxlength` specifies the maximum number of characters allowed in a text input.
- `minlength` specifies the minimum number of characters required in a text input.
Example:
<input type="text" name="password" maxlength="20" minlength="8">
7. step Attribute in `<input>` Element (for number input):
- The `step` attribute is used with `<input type="number">` to specify the increment or decrement
value when the user interacts with the input.
- It controls how much the value should change when using up/down arrows or spinner controls.
Example:
<input type="number" name="quantity" step="1">
8. enctype Attribute (Multipart Form Data):
- The `enctype` attribute specifies the encoding type for form data when file uploads are involved.
- For file uploads, you should use `enctype="multipart/form-data"` to ensure proper data
transmission.
Example:
<form action="upload.php" method="post" enctype="multipart/form-data">
<!-- File input element goes here -->
</form>