PHP code example of lcharette / uf_formgenerator

1. Go to this page and download the library: Download lcharette/uf_formgenerator 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/ */

    

lcharette / uf_formgenerator example snippets


// Load validator rules
$schema = new RequestSchema("schema://project.json");
$validator = new JqueryValidationAdapter($schema, $this->translator);

// Create the form
$form = new Form($schema, $project);

$view->render($response, "pages/myPage.html.twig", [
    "fields" => $form->generate(),
    "validators" => $validator->rules('json', true)
]);


$view->render($response, "FormGenerator/modal.html.twig", [
    "box_id"        => $get['box_id'],
    "box_title"     => "PROJECT.CREATE",
    "submit_button" => "CREATE",
    "form_action"   => '/project/create',
    "fields"        => $form->generate(),
    "validators"    => $validator->rules('json', true)
]);

// Get clients from the db model
$clients = Clients::all();

$form = new Form($schema);
$form->setInputArgument('clients', 'options', $clients);

$form = new Form($schema);
$form->setData($clients, $project);

$currentClient = ...

$form = new Form($schema, $project);
$form->setValue('clients', $currentClient);



namespace UserFrosting\Sprinkle\MySprinkle\Element;

use UserFrosting\Sprinkle\FormGenerator\Element\Input;

class Date extends Input
{
    protected function applyTransformations(): void
    {
        $this->element = array_merge([
            'class' => 'myDateElement',
            'value' => $this->getValue(),
            'name'  => $this->name,
            'id'    => 'field_' . $this->name,
            'date-foo' => //...
        ], $this->element);
    }
}

$form = new Form($schema, $project);
$form->registerType('date', UserFrosting\Sprinkle\MySprinkle\Element\Date::class);