HTML
π What is an HTML Form?
A form is a structure used to collect data from users.
Examples:
- Login form
- Registration form
- Search box
- Comment section
Forms usually start like this:
HTML
<form>
<!-- form elements go here -->
</form>
π 2. Basic Attributes of a Form
HTML
<form action="islem.php" method="post">
πΉ action:
Specifies where the data will be sent when the form is submitted.
πΉ method
Specifies how the data will be sent:
- get β visible in the URL
- post β sent hidden (more secure)
π 3. The Most Important Form Element: input
HTML
<input type="text">
But the function of the input changes depending on the type
π 4. Input Types (VERY IMPORTANT)
πΉ 1. Text (Text field)
HTML
<input type="text" name="title">
πΉ 2. Password
HTML
<input type="password" name="pass">
πΉ 3. Email
HTML
<input type="email" name="email">
Performs automatic validation
πΉ 4. Number
HTML
<input type="number" min="1" max="100">
πΉ 5. Radio (Single choice)
HTML
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female
Same name β only one can be selected
πΉ 6. Checkbox (Multiple choice)
HTML
<input type="checkbox" name="hobby" value="sport"> Sports
<input type="checkbox" name="hobby" value="music"> Music
πΉ 7. Submit
HTML
<input type="submit" value="Submit">
πΉ 8. File (File upload)
HTML
<input type="file">
πΉ 9. Date
HTML
<input type="date">
π 5. Label
Very important for user experience:
HTML
<label>Your Name:</label>
<input type="text">
π Better usage:
HTML
<label for="name">Your Name:</label>
<type="text" id="name">
Clicking the label activates the input
π 6. Textarea (Long text field)
HTML
<textarea rows="5" cols="30"></textarea>
π Examples:
- Comment section
- Message box
π 7. Select (Dropdown Menu)
HTML
<select>
<option>Turkey</option>
<option>Germany</option>
</select>
π 8. Button
HTML
<select>
<button>Submit</button>
</select>
π 9. Required (Mandatory field)
HTML
<input type="text" required>
Cannot be submitted empty
π 10. Placeholder (Hint text)
HTML
<input type="text" placeholder="Enter your name">
π 11. Pattern (Regex validation)
HTML
<input type="text" pattern="[0-9]{11}">
Requires an 11-digit number
π 12. A Real Form Example
π₯ Letβs combine everything:
HTML
<form action="kayit.php" method="post">
<label>Name:</label>
<input type="text" name="names" required><br><br>
<label>Email:</label>
<input type="email" name="email" required><br><br>
<label>Password:</label>
<input type="password" name="pass"><br><br>
<label>Gender:</label>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female<br><br>
<label>Hobbies:</label>
<input type="checkbox" name="hobby" value="sport"> Sport
<input type="checkbox" name="hobby" value="music"> Music<br><br>
<label>Country:</label>
<select name="country">
<option>Turkey:</option>
<option>Germany:</option>
</select><br><br>
<label>Message:</label><br>
<textarea name="message"></textarea><br><br>
</form>
π 13. GET vs POST (IMPORTANT)
πΉ GET
HTML
site.com?ad=Alice
Visible in URL
For small data
πΉ POST
Not visible in URL
More secure
Preferred for forms
π 14. Why is name Important?
HTML
<input name="email">
π Data sent to backend:
HTML
email=example@mail.com
If there is no name, the data is not sent!
Summary
- HTML Form =
<form>+ input + user data - Most important parts:
- form
- input
- name
- method
- action
