AppML β How to Handle Form Submission: Simple Data Saving Without JavaScript
Introduction β Why Learn Form Submission in AppML?
Handling form submissions often requires JavaScript, AJAX, or backend scriptingβbut not with AppML. Using models, data attributes, and the appml-submit button, you can create and submit fully functional forms with zero JavaScript.
In this guide, youβll learn:
- How to define and use an AppML form
- How to use
appml-submitfor submitting data - How to connect models to PHP or ASP scripts
- How validation and saving happens automatically
Basic Concept β How AppML Handles Forms
AppML uses a model-driven form system, where:
- The model defines what fields are used and required.
- The
appml-dataattribute points to the backend handler (usually PHP/ASP). - The
appml-submitbutton triggers saving the form data. - AppML manages validation, updates, and messages automatically.
Example β Simple Form with AppML
user-model.json
{
"table": "users",
"key": "id",
"fields": [
{ "name": "name", "required": true },
{ "name": "email", "required": true },
{ "name": "role" }
]
}
This defines:
- A
userstable with a primary keyid - Required fields:
name,email
user-form.php
<?php
include("appml.php");
$appml = new AppML();
$appml->model = "user-model.json";
$appml->run();
?>
This PHP script:
- Loads the model
- Connects to the database (configured in
appml.php) - Handles form data save/update
HTML Form
<div
appml-model="user-model.json"
appml-data="user-form.php"
appml-message>
<h2>New User Registration</h2>
<input name="name" placeholder="Full Name">
<input name="email" placeholder="Email">
<input name="role" placeholder="Role">
<button appml-submit>Submit</button>
</div>
Explanation:
- The form fields match model field names (
name,email,role) - AppML automatically maps the inputs to the model
appml-submittriggers the form save via AJAX touser-form.php- Any errors or success messages appear automatically
Example β Update Existing Record
You can also use AppML to edit records:
<div
appml-model="user-model.json"
appml-data="user-form.php"
appml-key="3"
appml-message>
<input name="name">
<input name="email">
<input name="role">
<button appml-submit>Update</button>
</div>
appml-key="3" loads the record with ID 3 for editing.
Form Validation with onvalidate()
You can add custom validation using a controller.
form-controller.js
myAppML.onvalidate = function() {
if (!myAppML.data.email.includes("@")) {
myAppML.message = "Please enter a valid email address.";
return false;
}
return true;
};
This ensures the email is properly formatted before submission.
Backend Handling in PHP
AppML expects your backend to:
- Read the model
- Connect to the database
- Handle INSERT, UPDATE, DELETE based on the model
Make sure your appml.php file is configured to connect to your SQL database.
Display Submission Message
AppML automatically uses appml-message to show messages like:
"Record inserted successfully.""Validation failed."
You can customize messages using controllers or model settings.
Summary β Recap & Key Takeaways
AppML simplifies form creation by binding HTML fields to a model and handling the form submission automatically with a server script.
Key Takeaways:
- Use
appml-modelfor field definitions and validation - Use
appml-datato point to a PHP/ASP script for data handling - Use
appml-submitto submit the form - Add
appml-messageto show success/error feedback - Add
appml-keyto edit existing records
AppML form submission is a powerful low-code approach to building interactive apps with minimal scripting.
FAQs β Handling Forms with AppML
Can I use GET instead of POST for AppML forms?
No. AppML submits data using POST for inserts and updates.
What happens if a required field is left blank?
AppML will prevent submission and show a validation error based on the model.
Can I use radio buttons, checkboxes, or dropdowns in AppML forms?
Yes. Just use standard HTML form controls with matching name attributes.
Can I handle file uploads with AppML forms?
File uploads are not natively supported. You need to extend the form with custom JavaScript.
Is AppML secure for public form handling?
Use secure server-side validation in PHP and restrict unauthorized SQL operations.
Share Now :
