π 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 :
