2017 © Pedro Peláez
 

library micro-form

Form builder

image

fullstackpe/micro-form

Form builder

  • Monday, July 2, 2018
  • by marcomilon
  • Repository
  • 1 Watchers
  • 1 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

micro-form

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

Installation

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

composer require fullstackpe/micro-form, (*3)

If you prefer you can create a composer.json in your project folder., (*4)

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

How it works?

Create a jsform object., (*5)

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., (*6)

Examples, (*7)

Input, (*8)

<?php

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

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

output, (*9)

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

Textarea, (*10)

<?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, (*11)

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

Select, (*12)

<?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, (*13)

<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., (*14)

License

This library is released under the MIT License., (*15)

The Versions

02/07 2018

dev-master

9999999-dev

Form builder

  Sources   Download

MIT

The Requires

 

The Development Requires

json form builder

02/05 2018

2.0.0

2.0.0.0

Form builder

  Sources   Download

MIT

The Requires

 

The Development Requires

json form builder

02/03 2018

1.0.0

1.0.0.0

Form builder

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

json form builder