πŸ“š AppML How-To Guides
Estimated reading: 4 minutes 54 views

πŸ“ 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-submit for 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:

  1. The model defines what fields are used and required.
  2. The appml-data attribute points to the backend handler (usually PHP/ASP).
  3. The appml-submit button triggers saving the form data.
  4. 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 users table with a primary key id
  • 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-submit triggers the form save via AJAX to user-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-model for field definitions and validation
  • Use appml-data to point to a PHP/ASP script for data handling
  • Use appml-submit to submit the form
  • Add appml-message to show success/error feedback
  • Add appml-key to 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

AppML – How to Handle Form Submission

Or Copy Link

CONTENTS
Scroll to Top