143 lines
8.2 KiB
HTML
143 lines
8.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<link rel="icon" type="image/svg+xml" href="../../../assets/favicon.svg">
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>HTML 03: Formulare & Validierung</title>
|
|
<link rel="stylesheet" href="../../../assets/style.css">
|
|
</head>
|
|
<body>
|
|
<div class="app-layout">
|
|
<div class="app-main">
|
|
<header>
|
|
<div class="header-container">
|
|
<div class="header-badge">🌱 Lehrpfad 1: Semantisches HTML5</div>
|
|
<h1>HTML 03: Formulare & HTML5-Validierung</h1>
|
|
<p>Lerne die Konstruktion interaktiver Web-Formulare, barrierefreie <code><label></code>-Zuordnungen, moderne Eingabetypen und native Client-Side Validierung ohne JavaScript.</p>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container">
|
|
<!-- 1. THEORIE: FORMULAR-AUFBAU & LABELS -->
|
|
<section class="card">
|
|
<h2>💡 1. Formular-Grundgerüst & Barrierefreie Labels</h2>
|
|
<p>Ein Formular wird mit dem <code><form></code>-Tag deklariert. Jedes Eingabefeld benötigt ein zugehöriges <code><label for="feld-id"></code>, dessen <code>for</code>-Attribut exakt mit der <code>id</code> des Feldes übereinstimmt:</p>
|
|
|
|
<pre><code><form action="/api/register" method="POST">
|
|
<div class="form-group">
|
|
<label for="username">Benutzername:</label>
|
|
<input type="text" id="username" name="username" required minlength="3" placeholder="z.B. dev_anna">
|
|
</div>
|
|
|
|
<button type="submit">Registrieren</button>
|
|
</form></code></pre>
|
|
</section>
|
|
|
|
<!-- 2. THEORIE: INPUT-TYPEN & AUSWAHL -->
|
|
<section class="card">
|
|
<h2>🎛️ 2. Moderne Input-Typen, Dropdowns & Textareas</h2>
|
|
<p>HTML5 bietet spezialisierte Eingabetypen für mobile Tastaturen (z.B. <code>email</code> blendet auf Smartphones das @-Zeichen ein, <code>number</code> das Ziffernpad):</p>
|
|
|
|
<pre><code><!-- E-Mail mit Formatprüfung: -->
|
|
<label for="user-email">E-Mail-Adresse:</label>
|
|
<input type="email" id="user-email" name="email" required>
|
|
|
|
<!-- Zahlenbereich mit min & max: -->
|
|
<label for="experience">Jahre Erfahrung:</label>
|
|
<input type="number" id="experience" name="experience" min="0" max="50" value="1">
|
|
|
|
<!-- Dropdown-Auswahl: -->
|
|
<label for="course-select">Gewünschter Kurs:</label>
|
|
<select id="course-select" name="course" required>
|
|
<option value="">-- Bitte wählen --</option>
|
|
<option value="html">HTML5 & CSS3 Grundlagen</option>
|
|
<option value="js">JavaScript Masterclass</option>
|
|
</select>
|
|
|
|
<!-- Mehrzeiliges Textfeld: -->
|
|
<label for="motivation">Dein Motivationsschreiben:</label>
|
|
<textarea id="motivation" name="motivation" rows="4" placeholder="Erzähle über dich..."></textarea></code></pre>
|
|
</section>
|
|
|
|
<!-- 3. THEORIE: VALIDIERUNG -->
|
|
<section class="card">
|
|
<h2>🛡️ 3. Native HTML5-Validierungsattribute</h2>
|
|
<p>Der Browser kann Eingaben vor dem Absenden vollständig ohne JavaScript prüfen:</p>
|
|
|
|
<div style="overflow-x: auto; margin: 15px 0;">
|
|
<table style="width: 100%; border-collapse: collapse; font-size: 0.9rem;">
|
|
<thead>
|
|
<tr style="border-bottom: 2px solid var(--border-color); background: var(--bg-subtle);">
|
|
<th style="padding: 10px;">Attribut</th>
|
|
<th style="padding: 10px;">Funktion</th>
|
|
<th style="padding: 10px;">Beispiel</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>required</code></td>
|
|
<td style="padding: 10px;">Pflichtfeld, darf nicht leer sein</td>
|
|
<td style="padding: 10px;"><code><input type="email" required></code></td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>minlength / maxlength</code></td>
|
|
<td style="padding: 10px;">Minimale und maximale Zeichenanzahl</td>
|
|
<td style="padding: 10px;"><code><input type="password" minlength="8"></code></td>
|
|
</tr>
|
|
<tr style="border-bottom: 1px solid var(--border-color);">
|
|
<td style="padding: 10px;"><code>min / max / step</code></td>
|
|
<td style="padding: 10px;">Zahlen- und Datumsgrenzen</td>
|
|
<td style="padding: 10px;"><code><input type="number" min="1" max="100"></code></td>
|
|
</tr>
|
|
<tr>
|
|
<td style="padding: 10px;"><code>pattern</code></td>
|
|
<td style="padding: 10px;">Regulärer Ausdruck (Regex) zur Validierung</td>
|
|
<td style="padding: 10px;"><code><input pattern="[0-9]{5}"></code> (Postleitzahl)</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="box box-analogie">
|
|
<div class="box-title">🚦 Didaktische Analogie: Die automatische Passkontrolle</div>
|
|
<p><strong>Das <code><label for="..."></code></strong> ist das Schild am Schalter. Wenn du auf das Schild klickst, aktiviert der Browser sofort das zugehörige Eingabefeld (wichtig für Motorik und Screenreader!).</p>
|
|
<p><strong>Die HTML5-Validierung</strong> ist die Schranke am Gate: Ist das Feld <code>required</code> oder das Passwort zu kurz, schlägt der Browser sofort Alarm und lässt den Nutzer gar nicht erst zum Server durch!</p>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- 4. AUFGABEN CHECKLISTE -->
|
|
<section class="card">
|
|
<h2>🎯 Aufgaben & Checkliste in <code>aufgabe.html</code></h2>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t1">
|
|
<label class="task-label" for="t1"><strong>TODO 1:</strong> <code><form></code> mit <code>action</code> und <code>method="POST"</code> erstellen, unterteilt mit <code><fieldset></code> und <code><legend></code>.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t2">
|
|
<label class="task-label" for="t2"><strong>TODO 2:</strong> Text- und E-Mail-Inputs mit barrierefreien <code><label for="..."></code> und <code>required</code>-Attribut anlegen.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t3">
|
|
<label class="task-label" for="t3"><strong>TODO 3:</strong> Passwort-Feld mit <code>minlength="8"</code> und Number-Input mit <code>min="1"</code> und <code>max="50"</code> integrieren.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t4">
|
|
<label class="task-label" for="t4"><strong>TODO 4:</strong> Dropdown-Menü <code><select></code> mit mehreren <code><option></code>-Werten sowie ein <code><textarea></code>-Feld einbinden.</label>
|
|
</div>
|
|
<div class="task-item">
|
|
<input type="checkbox" class="task-checkbox" id="t5">
|
|
<label class="task-label" for="t5"><strong>TODO 5:</strong> Checkbox für AGB (<code>required</code>) und einen <code><button type="submit"></code> zum Absenden hinzufügen.</label>
|
|
</div>
|
|
|
|
<div style="margin-top: 25px; display: flex; gap: 12px; flex-wrap: wrap;">
|
|
<a href="../../../workspace.html?course=html_css&track=track_1_html_basics&chapter=03_formulare_und_validierung" class="btn" style="background: #eab308; color: #000; font-weight: 700;">💻 In Web-IDE öffnen →</a>
|
|
<a href="../02_texte_listen_und_medien/index.html" class="btn btn-secondary">← Zurück zu HTML 02</a>
|
|
<a href="../04_barrierefreiheit_und_aria/index.html" class="btn btn-secondary">Weiter zu HTML 04 →</a>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|