PHP code example of luca-simonetti / liform

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

    

luca-simonetti / liform example snippets


use Limenius\Liform\Resolver;
use Limenius\Liform\Liform;
use Limenius\Liform\Liform\Transformer;

$resolver = new Resolver();
$resolver->setTransformer('text', Transformer\StringTransformer);
$resolver->setTransformer('textarea', Transformer\StringTransformer, 'textarea');
// more transformers you might need, for a complete list of what is used in Symfony
// see https://github.com/Limenius/LiformBundle/blob/master/Resources/config/transformers.xml
$liform = new Liform($resolver);

$form = $this->createForm(CarType::class, $car, ['csrf_protection' => false]);
$schema = json_encode($liform->transform($form));


use Limenius\Liform\Liform;

$stringTransformer = $this->get('liform.transformer.string');

$resolver = $this->get('liform.resolver');
$resolver->setTransformer('file', $stringTransformer, 'file_widget');
$liform = new Liform($resolver);

use Limenius\Liform\Serializer\Normalizer\FormViewNormalizer;

$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new FormViewNormalizer());

$serializer = new Serializer($normalizers, $encoders);
$initialValues = $serializer->normalize($form),

use Limenius\Liform\Serializer\Normalizer\FormErrorNormalizer;

$encoders = array(new XmlEncoder(), new JsonEncoder());
$normalizers = array(new FormErrorNormalizer());

$serializer = new Serializer($normalizers, $encoders);
$errors = $serializer->normalize($form),

class DummyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('someText', Type\TextType::class);
    }
}

class DummyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('someText', Type\TextType::class, [
                'liform' => [
                    'widget' => 'my_widget'
                ]
            ]);
    }
}

class DummyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('someText', Type\TextType::class, [
                'label' => 'Some text',
            ]);
    }
}

class DummyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('someText', Type\TextType::class, [
                'attr' => [
                    'pattern' => '.{5,}',
                ],
            ]);
    }
}


class DummyType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('someText', Type\TextType::class, [
                'label' => 'Some text',
                'liform' => [
                    'description' => 'This is a help message',
                ]
            ]);
    }
}