James Williams
Birmingham Newman University
jwilliams@staff.newman.ac.uk
3-hour session
<form action="/submit" method="post">
<input type="text" name="username">
<button type="submit">Submit</button>
</form>
See Moodle for supporting materials.
Comprehensive guide to creating and styling HTML forms
<form action="destination.php" method="post">
<!-- Form elements go here -->
<input type="text" name="field_name">
<button type="submit">Submit Form</button>
</form>
action: Where the form data is sentmethod: How the data is sent (GET or POST)name: Identifies the field for processing<!-- GET Method -->
<form action="/search" method="get">
<input type="text" name="query">
</form>
<!-- POST Method -->
<form action="/register" method="post">
<input type="text" name="username">
</form>
<input type="text" name="username" placeholder="Enter username">
<input type="email" name="email" placeholder="Enter email">
<input type="password" name="password" placeholder="Enter
password">
<input type="tel" name="phone" placeholder="Enter phone number">
See Moodle for supporting materials.
Learn about different HTML form input types and their attributes
<input type="text"
name="username"
placeholder="Enter username"
required
maxlength="20"
minlength="3"
value="default_value"
disabled
>
required: Field must be filledplaceholder: Hint textmaxlength/minlength: Character limitsvalue: Default value<textarea name="message" rows="4" cols="50" placeholder="Enter your
message"></textarea>
rows and cols set dimensions<select name="country">
<option value="">Select a country</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
<option value="ca">Canada</option>
</select>
<p>Select your gender:</p>
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>
<input type="radio" name="gender" value="other" id="other">
<label for="other">Other</label>
Select your gender:
<p>Select your interests:</p>
<input type="checkbox" name="interests" value="sports" id="sports">
<label for="sports">Sports</label>
<input type="checkbox" name="interests" value="music" id="music">
<label for="music">Music</label>
<input type="checkbox" name="interests" value="reading" id="reading">
<label for="reading">Reading</label>
Select your interests:
<input type="file" name="upload" accept="image/*">
<input type="file" name="document" accept=".pdf,.doc,.docx">
<input type="file" name="multiple" multiple>
accept specifies allowed file typesmultiple allows multiple file selection<input type="date" name="birthdate">
<input type="time" name="meeting_time">
<input type="datetime-local" name="event_datetime">
<input type="month" name="start_month">
<input type="number" name="age" min="0" max="120" step="1">
<input type="range" name="rating" min="1" max="10" value="5">
<input type="color" name="favorite_color">
<!-- Method 1: Label with for attribute -->
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<!-- Method 2: Wrapping label -->
<label>
Email: <input type="email" name="email">
</label>
<input type="email" name="email" required>
<input type="text" name="username" pattern="[A-Za-z]{3,}" title="3+ letters
only">
<input type="number" name="age" min="18" max="65">
<input type="url" name="website">
required: Field must be filledpattern: Custom validation with regexmin/max: Numeric limitsTry typing in the fields to see real-time validation in action!
<fieldset>
<legend>Personal Information</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
</fieldset>
<button type="submit">Submit Form</button>
<button type="reset">Clear Form</button>
<button type="button">Custom Action</button>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
contact-form.htmlTime: 45 minutes
This task will help you understand form structure and input types
Take a break, ask questions, or catch up on the previous task.
Next: Secondary slides and Task 2
<label> elements<!-- Simple email form -->
<form action="mailto:contact@example.com" method="post"
enctype="text/plain">
<input type="text" name="name">
<button type="submit">Send Email</button>
</form>
Time: 45 minutes
This task will help you understand advanced form features and validation
CSS Fundamentals - Styling your HTML content