PHP code example of userfrosting / fortress
1. Go to this page and download the library: Download userfrosting/fortress 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' );
userfrosting / fortress example snippets
{
" " php": " >=5.6 .0 ",
" userfrosting/fortress": " ^4.2 .0 "
}
}
$schema = new \UserFrosting\Fortress\RequestSchema\RequestSchemaRepository($loader->load());
$post = [
"puppies" => "<script>I'm definitely really a puppy </script>0 " ,
"horses" => "seven pretty horses"
];
$transformer = new \UserFrosting\Fortress\RequestDataTransformer($schema);
$transformedData = $transformer->transform($post, "skip" );
echo "<h2>Transformed data</h2>" ;
echo "<pre>" ;
print_r($transformedData);
echo "</pre>" ;
$validator = new \UserFrosting\Fortress\ServerSideValidator($schema, $translator);
if (!$validator->validate($transformedData)) {
echo "<h2>Validation results</h2>" ;
echo "<pre>" ;
print_r($validator->errors());
echo "</pre>" ;
}
$clientVal = new \UserFrosting\Fortress\Adapter\JqueryValidationAdapter($schema, $translator);
echo "<h2>Client-side validation schema (JSON)</h2>" ;
echo "<pre>" ;
print_r($clientVal->rules());
echo "</pre>" ;
$clientVal = new \UserFrosting\Fortress\Adapter\JqueryValidationAdapter($schema, $translator);
echo "<h2>Client-side validation schema (JSON)</h2>" ;
echo "<pre>" ;
print_r($clientVal->rules('json' ,false ,'mycoolform1' ));
echo "</pre>" ;