2017 © Pedro Peláez
 

library json-schema-form

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

image

kingsquare/json-schema-form

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  • Monday, August 15, 2016
  • by Reggino
  • Repository
  • 4 Watchers
  • 20 Stars
  • 2,127 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

Generate forms based on JSON Schema

A framework-agnostic PHP Implementation for generating simple forms based on json-schema . This package is compatible with version 4 and may be combined with, (*1)

  • Client-side validation (E.g. http://jqueryvalidation.org/)
  • Server-side validation (E.g. https://packagist.org/packages/justinrainbow/json-schema)

Installation

Library

$ wget http://getcomposer.org/composer.phar
$ php composer.phar install --save kingsquare/json-schema-forms

Usage

retrieve('file://' . realpath('schema.json'));

// Generate
$formGenerator = new JsonSchemaForm\Generator($schema);
echo $formGenerator->render();
?>

See examples folder for a few more options., (*2)

Extra styling and JavaScript is required for proper presentation and validation., (*3)

Process form data

To validate any data in the form against the schema, the form data should be casted to the proper datatypes. Validation of form data may look like, (*4)

<?php
$validator = new JsonSchema\Validator();
$dataParser = new JsonSchemaForm\DataParser();

//cast any posted form-data (strings) to the proper data-types
$data = $dataParser->parse($_POST['root'], $schema);

$validator->check($data, $this->schema);

$message = "The supplied JSON validates against the schema.\n";
if (!$validator->isValid()) {
    $message = "JSON does not validate. Violations:\n";
    foreach ($validator->getErrors() as $error) {
        $message .= print_r($error, true);
    }
}
echo $message;

Running the tests

$ phpunit

The Versions

15/08 2016

dev-master

9999999-dev

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare

10/07 2014

0.6

0.6.0.0

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare

10/07 2014

0.5

0.5.0.0

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare

09/07 2014

0.4

0.4.0.0

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare

09/07 2014

0.3

0.3.0.0

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare

09/07 2014

0.2

0.2.0.0

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare

09/07 2014

0.1

0.1.0.0

A framework-agnostic PHP Implementation for generating simple forms based on json-schema

  Sources   Download

The Requires

 

by Kingsquare