PHP code example of lekoala / kaly-forms

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

    

lekoala / kaly-forms example snippets


$forms = new FormFactory($renderer);
$form = $forms->create(...)->withState($state);

// In a plain PHP template:
<?= $form 

$form = $forms->create(
    name: 'login',
    action: '/login',
    children: [
        new EmailField('email', label: 'Email', n')],
);

final class MoneyField extends Field
{
    public function __construct(
        string $name,
        ?string $label = null,
        public readonly string $currency = 'EUR',
    ) {
        parent::__construct($name, $label);
    }
}

$renderers->register(
    MoneyField::class,
    fn(FormNode $node, RenderContext $context): Html => ...,
);

new CustomElementField(
    name: 'address',
    tag: 'address-picker',
    label: 'Address',
    attributes: ['data-country-field' => 'country'],
)

<?= $form 

$result = $inputs->mapResult($request, RegistrationInput::class);

$state = FormState::from(
    values: $result->values(),
    errors: KalyFormErrors::fromValidation($result->validation()),
);

$form = $registrationForm->create(
    csrf: $csrf->token('registration'),
)->withState($state);

return new View('registration/edit', ['form' => $form]);

<?= $form 

$renderer = new HtmlRenderer();
$forms = new FormFactory($renderer);

$form = $forms->create(...);
$state = FormState::from($request->getParsedBody() ?? [], $errors);

return $response->withBody(stream((string) $form->withState($state)));