PHP Classes

PHP JSON Form Builder: Generate a HTML form definition in JSON format

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 475 This week: 1All time: 5,979 This week: 560Up
Version License PHP version Categories
json-form-generator 1.3MIT/X Consortium ...5HTML, PHP 5
Description 

Author

This class can generate a HTML form definition in JSON format.

It takes as parameter the path of a JSON file and parses it to extract the definition of the form options as well the options of all the inputs contained in the form.

The class generates HTML for the form and its inputs.

Innovation Award
PHP Programming Innovation award nominee
April 2020
Number 3
Many Web applications need to render forms to get information from their users.

This class provides an easy way to generate HTML forms from files with definitions read from a file in JSON format.

Manuel Lemos
Picture of Arash Soleimani
  Performance   Level  
Name: Arash Soleimani <contact>
Classes: 4 packages by
Country: The Netherlands The Netherlands
Age: ???
All time rank: 286176 in The Netherlands The Netherlands
Week rank: 411 Up9 in The Netherlands The Netherlands Up
Innovation award
Innovation award
Nominee: 2x

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LeoMoon JSON Form Generator</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" crossorigin="anonymous" />
    <style>
        body{ padding:50px; }
        label{ display:block; }
        input{ padding:5px; }
        select{ width:100px; padding:5px;}
    </style>
</head>
<body>
            <?php
               
require_once('form.class.php');
               
$form = new Form(['file'=>'./example_form.json']);
               
$form->show();
           
?>
</body>
</html>


Details

JSON Form Generator

LeoMoon JFG generates HTML form tags from JSON file/input. JFG supports all types and attributes of form tags.

Why JSON?

Companies change their software every couple of years. If they have too many pages and forms, they need to redesign the whole thing again. But when you are using JSON format, you don't have to worry about redesigning everything. You just write a new JSON render engine in a new programming language or framework. Here is an example:

Documentation

Usage

  require_once('form.class.php');
  $form = new Form(['file'=>'./example_form.json']);
  $form->show();

Sample JSON file

{
    "name": "formName",
    "title": "Registration form",
    "description": "simple JFG example.",
    "method": "post",
    "action": "http://leomoon.com",
    "properties": {
      "firstName": {
        "type": "input",
        "title": "First name",
        "name":"firstName",
        "value": "test",
        "required": true,
        "onChange":"console.log(this.value)"
      },
      "lastName": {
        "type": "input",
        "title": "Last name",
        "name":"lastName",
        "disabled": true
      },
      "age": {
        "type": "number",
        "title": "Age",
        "name":"age"
      },
      "bio": {
        "type": "input",
        "title": "Bio",
        "name":"bio",
        "placeholder":"Biography"
      },
      "password": {
        "type": "password",
        "title": "Password",
        "name":"password",
        "min": 3
      },
      "language": {
        "type": "select",
        "title": "Language",
        "name":"lang",
        "options":
            {"en":"English",
            "fa":"Farsi",
            "de":"German"
            }
      },
      "submit": {
        "type": "submit",
        "title": "Save Form",
        "name":"submit"
      }
    }
  }

Screenshots  
  • json-form-generator-sample.jpg
  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file example_form.json Data Auxiliary data
Plain text file form.class.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 83%
Total:475
This week:1
All time:5,979
This week:560Up