π AppML β Forms and Form Validation: Build Smart Forms Without JavaScript
π§² Introduction β Why Use AppML for Forms?
Forms are the core of user input across the web. Whether itβs signing up users, collecting feedback, or processing ordersβforms are essential. With AppML, you can build smart, validated forms using just HTML + JSON + Models. No JavaScript or backend code is required for basic setups.
π― What you’ll learn:
- Create dynamic forms using AppML
- Use
appml-model
to apply validation rules - Bind form input to data sources with
appml-data
- Handle submission using
appml-submit
- Show success/error messages with
appml-message
π§ Step-by-Step: Create a Simple Contact Form
π Model File β models/contact-model.json
{
"key": "id",
"fields": [
{ "name": "name", "required": true },
{ "name": "email", "required": true },
{ "name": "message", "required": true }
]
}
π Explanation:
"key": "id"
β Unique identifier for each contact entry."fields"
β Defines each input field:name
,email
,message
β All marked"required": true
, so the form will not submit if any of them are empty.
π Data File β data/contacts.json
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"message": "Hi, this is great!"
}
]
π Explanation:
- This JSON array stores previously submitted form data.
- AppML will fetch and append to this file when form data is submitted (if backend logic is implemented).
π₯οΈ HTML File β contact.html
<div
appml-model="models/contact-model.json"
appml-data="data/contacts.json"
appml-message>
<h2>Contact Us</h2>
<input name="name" placeholder="Your Name">
<input name="email" type="email" placeholder="Your Email">
<textarea name="message" placeholder="Your Message"></textarea>
<button appml-submit>Send</button>
</div>
π Explanation (line-by-line):
<div>
β This is the AppML form container.appml-model="..."
links to the model that defines field rules.appml-data="..."
binds this form to the contacts data file.appml-message
allows AppML to show success/error messages here.
<input name="name">
β Binds user name input to thename
field in the model.<input name="email" type="email">
β Binds to theemail
field and uses HTML5 validation.<textarea name="message">
β Binds to themessage
field.<button appml-submit>
β Submits the form. AppML will validate and handle the data automatically.
π Example: Order Form With Number Validation
π Model File β models/order-model.json
{
"key": "id",
"fields": [
{ "name": "product", "required": true },
{ "name": "quantity", "required": true, "datatype": "number" }
]
}
π Explanation:
- Two fields:
product
β Must be filled out.quantity
β Required and must be a number.
π₯οΈ HTML Order Form β order.html
<div
appml-model="models/order-model.json"
appml-data="data/orders.json"
appml-message>
<h2>Place Your Order</h2>
<input name="product" placeholder="Product Name">
<input name="quantity" type="number" placeholder="Quantity">
<button appml-submit>Order Now</button>
</div>
π Explanation:
appml-model="..."
loads validation for product and quantity.appml-data="..."
binds toorders.json
, where form entries will be stored.input name="product"
β Tied to theproduct
field.input name="quantity"
β Must be a number due to the model rule andtype="number"
.
β Add Real-Time Validation with a Controller
π§ JavaScript File β controllers/contact.js
myAppML.onvalidate = function() {
if (!myAppML.data.email.includes("@")) {
myAppML.message = "Invalid email format.";
return false;
}
return true;
};
π Explanation:
onvalidate
is called before submission.myAppML.data.email
checks if the input contains an@
symbol.myAppML.message
displays an error if validation fails.return false
blocks submission.
π¬ Add Controller to HTML
<div
appml-model="models/contact-model.json"
appml-data="data/contacts.json"
appml-controller="controllers/contact.js"
appml-message>
<!-- Form contents -->
</div>
π Adds controller logic to the form. AppML will auto-run the script on validation.
π§° AppML Form Attribute Overview
Attribute | Description |
---|---|
appml-model | Specifies validation rules via a JSON model file |
appml-data | Binds form data to a backend endpoint or JSON file |
appml-controller | Adds advanced logic for validation or processing |
appml-submit | Submits the form and triggers validation |
appml-message | Displays success or error messages |
π Summary β Recap & Key Takeaways
AppML lets you build complete, validated forms using HTML-only syntax powered by declarative data and model files. You can handle user input, validate it, and manage messages all without custom JavaScript.
π Key Takeaways:
- Define validation rules in
appml-model
- Bind your forms to data sources using
appml-data
- Submit and process data with
appml-submit
- Display feedback with
appml-message
- Add extra validation with
appml-controller
if needed
βοΈ AppML forms are perfect for contact pages, surveys, admin panels, and classroom appsβoffering low-code power with high usability.
β FAQs β AppML Forms and Validation
β Can I submit the form to a backend script like PHP?
β
Yes. Use a server-side appml-data
endpoint (e.g., data.php
) instead of a static JSON file.
β Does HTML5 validation work together with AppML?
β
Yes. Browser validation (e.g., type="email"
) complements AppML model rules.
β How do I reset a form after submission?
β
Use a <button type="reset">Reset</button>
or script it with AppMLβs controller if needed.
β Can I style appml-message
output?
β
Absolutely. Use custom CSS to format messages (e.g., error in red, success in green).
β Does AppML support dropdowns and radio buttons?
β
Yes. All standard HTML inputs work and bind using the name
attribute and model fields.
Share Now :