PHP code example of kingsquare / json-schema-form

1. Go to this page and download the library: Download kingsquare/json-schema-form library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kingsquare / json-schema-form example snippets




// Get the schema and data as objects
$retriever = new JsonSchema\Uri\UriRetriever;
$schema = $retriever->retrieve('file://' . realpath('schema.json'));

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


$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;