{ "$schema": "../../schemas/code-crispies-module-schema.json", "id": "html-forms-basic", "title": "HTML-Formulare: Grundlegende Eingaben", "description": "Lerne, Formulare mit verschiedenen Eingabetypen zu erstellen", "mode": "html", "difficulty": "beginner", "lessons": [ { "id": "form-structure", "title": "Formularstruktur", "description": "Jedes Formular benötigt einen <form>-Wrapper. Innerhalb verwendest du <label> zur Beschreibung der Eingaben und <input> für die Dateneingabe.

Das for-Attribut bei Labels sollte mit der id der Eingaben übereinstimmen für bessere Zugänglichkeit.", "task": "Erstelle ein Formular mit:
1. Einem <label> mit dem Text 'Name:' und dem for=\"name\"-Attribut
2. Einem Text-<input> mit id=\"name\" und name=\"name\"-Attributen", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 300px; } label { display: block; margin-bottom: 5px; font-weight: 500; } input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }", "sandboxCSS": "", "initialCode": "", "solution": "
\n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "element_exists", "value": "form", "message": "Umschließe alles mit einem <form>-Element" }, { "type": "element_exists", "value": "label", "message": "Füge ein <label> für deine Eingabe hinzu" }, { "type": "element_exists", "value": "input", "message": "Füge ein <input>-Element hinzu" }, { "type": "attribute_value", "value": { "selector": "label", "attr": "for", "value": null }, "message": "Füge ein for-Attribut zu deinem Label hinzu" }, { "type": "attribute_value", "value": { "selector": "input", "attr": "id", "value": null }, "message": "Füge ein id-Attribut zu deiner Eingabe hinzu" } ] }, { "id": "input-types", "title": "Eingabetypen", "description": "Verschiedene Eingabetypen bieten passende Tastaturen und Validierung:

type=\"text\" - Allgemeiner Text
type=\"email\" - E-Mail mit @-Validierung
type=\"password\" - Versteckte Zeichen
type=\"number\" - Numerische Tastatur
type=\"tel\" - Telefon-Tastatur", "task": "Erstelle ein Anmeldeformular mit zwei Feldern:
1. Ein E-Mail-Feld: <label for=\"email\">E-Mail:</label> und <input type=\"email\" id=\"email\">
2. Ein Passwort-Feld: <label for=\"password\">Passwort:</label> und <input type=\"password\" id=\"password\">", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 300px; } label { display: block; margin-top: 15px; margin-bottom: 5px; } label:first-child { margin-top: 0; } input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }", "sandboxCSS": "", "initialCode": "
\n \n
", "solution": "
\n \n \"email\" id=\"email\" name=\"email\">\n \n \n \"password\" id=\"password\" name=\"password\">\n
", "previewContainer": "preview-area", "validations": [ { "type": "element_exists", "value": "input[type='email']", "message": "Füge eine Eingabe mit type=\"email\" hinzu" }, { "type": "element_exists", "value": "input[type='password']", "message": "Füge eine Eingabe mit type=\"password\" hinzu" }, { "type": "element_count", "value": { "selector": "label", "min": 2 }, "message": "Füge Labels für beide Eingaben hinzu" } ] }, { "id": "submit-button", "title": "Absende-Button", "description": "Formulare benötigen eine Möglichkeit zum Absenden. Verwende:

<button type=\"submit\"> - Bevorzugt, flexibler Inhalt
<input type=\"submit\"> - Einfacher Text-Button

Der Button-Text sollte handlungsorientiert sein (z.B. 'Anmelden', 'Registrieren', 'Senden').", "task": "Füge dem Formular einen Absende-Button mit dem Text 'Anmelden' hinzu.", "previewHTML": "", "previewBaseCSS": "body { font-family: system-ui; padding: 20px; } form { max-width: 300px; } label { display: block; margin-top: 15px; margin-bottom: 5px; } label:first-child { margin-top: 0; } input { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } button { width: 100%; margin-top: 20px; padding: 10px; background: #1976d2; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background: #1565c0; }", "sandboxCSS": "", "initialCode": "
\n \n \"email\" id=\"email\">\n \n \n \"password\" id=\"password\">\n \n \n
", "solution": "
\n \n \"email\" id=\"email\">\n \n \n \"password\" id=\"password\">\n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "element_exists", "value": "button[type='submit'], input[type='submit']", "message": "Füge einen Absende-Button zu deinem Formular hinzu" }, { "type": "element_text", "value": { "selector": "button", "text": "Anmelden" }, "message": "Der Button sollte 'Anmelden' anzeigen" } ] } ] }