{ "$schema": "../schemas/code-crispies-module-schema.json", "id": "html-forms-basic", "title": "HTML Forms", "description": "Learn to create forms with various input types", "mode": "html", "difficulty": "beginner", "lessons": [ { "id": "form-structure", "title": "Form Structure", "description": "Every form needs a <form> wrapper. Inside, use <label> to describe inputs and <input> for user data entry.

The for attribute on labels should match the id on inputs for accessibility.", "task": "Create a form with:
1. A <label> with the text 'Name:' and for=\"name\" attribute
2. A text <input> with id=\"name\" and name=\"name\" attributes", "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": "Wrap everything in a <form> element" }, { "type": "element_exists", "value": "label", "message": "Add a <label> for your input" }, { "type": "element_exists", "value": "input", "message": "Add an <input> element" }, { "type": "attribute_value", "value": { "selector": "label", "attr": "for", "value": null }, "message": "Add a for attribute to your label" }, { "type": "attribute_value", "value": { "selector": "input", "attr": "id", "value": null }, "message": "Add an id attribute to your input" } ] }, { "id": "input-types", "title": "Input Types", "description": "Different input types provide appropriate keyboards and validation:

type=\"text\" - General text
type=\"email\" - Email with @ validation
type=\"password\" - Hidden characters
type=\"number\" - Numeric keyboard
type=\"tel\" - Phone keyboard", "task": "Create a login form with two fields:
1. An email field: <label for=\"email\">Email:</label> and <input type=\"email\" id=\"email\">
2. A password field: <label for=\"password\">Password:</label> and <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 \n \n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "element_exists", "value": "input[type='email']", "message": "Add an input with type=\"email\"" }, { "type": "element_exists", "value": "input[type='password']", "message": "Add an input with type=\"password\"" }, { "type": "element_count", "value": { "selector": "label", "min": 2 }, "message": "Add labels for both inputs" } ] }, { "id": "submit-button", "title": "Submit Button", "description": "Forms need a way to submit data. Use:

<button type=\"submit\"> - Preferred, flexible content
<input type=\"submit\"> - Simple text-only button

The button text should be action-oriented (e.g., 'Sign In', 'Register', 'Send').", "task": "Add a submit button to the form with the text 'Sign In'.", "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 \n \n \n \n \n
", "solution": "
\n \n \n \n \n \n \n \n
", "previewContainer": "preview-area", "validations": [ { "type": "element_exists", "value": "button[type='submit'], input[type='submit']", "message": "Add a submit button to your form" }, { "type": "element_text", "value": { "selector": "button", "text": "Sign In" }, "message": "The button should say Sign In" } ] } ] }