Giter VIP home page Giter VIP logo

micro-form's Introduction

micro-form

Micro-form is a library to translate any datasource into into html form elements. Only Json Objects can be use as datasources.

Installation

First you need to install Composer. You may do so by following the instructions at getcomposer.org. After that run

composer require fullstackpe/micro-form

If you prefer you can create a composer.json in your project folder.

{
    "require": {
        "fullstackpe/micro-form": "^3.0"
    }
}

How it works?

Create a jsform object.

use micro\FormFactory;
$jsonForm = FormFactory::jsonForm();
echo $jsonForm->render($json);

then call render to get the form elements. The render method accepts a Json Object.

Examples

Input

<?php

$json = '[
    {
        "tag": "input",
        "type": "text",
        "name": "username",
        "class": "form-control"
    }
]';

use micro\FormFactory;
$jsonForm = FormFactory::jsonForm();
echo $jsonForm->render($json);

output

<input type="text" name="username" class="form-control">

Textarea

<?php

$json = '[
    {
        "tag": "textarea",
        "id": "story",
        "name": "story",
        "rows": "5",
        "cols": "33",
        "value": "It was a dark and stormy night..."
    }
]';

use micro\FormFactory;
$jsonForm = FormFactory::jsonForm();
echo $jsonForm->render($json);

output

<textarea id="story" name="story" rows="5" cols="33">
It was a dark and stormy night...
</textarea>

Select

<?php

$json = '[
    {
        "tag": "select",
        "name": "pets",
        "id": "pet-select",
        "value": [
            {
                "tag": "option",
                "label": "--Please choose an option--",
                "value": ""
            },
            {
                "tag": "option",
                "label": "Dog",
                "value": "dog"
            },
            {
                "tag": "option",
                "label": "Cat",
                "value": "cat"
            }
        ]
    }
]';

use micro\FormFactory;
$jsonForm = FormFactory::jsonForm();
echo $jsonForm->render($json);

output

<select name="pets" id="pet-select">
    <option value="">--Please choose an option--</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
</select>

Contribution

Feel free to contribute! Just create a new issue or a new pull request.

License

This library is released under the MIT License.

micro-form's People

Contributors

marcomilon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.