PHP code example of lin3s / wp-symfony-form

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

    

lin3s / wp-symfony-form example snippets


use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints;

class ContactType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', TextType::class, [
                'constraints' => new Constraints\NotBlank(),
                'label'       => 'Name',
            ])
            ->add('surname', TextType::class, [
                'constraints' => new Constraints\NotBlank(),
                'label'       => 'Surname',
            ])
            ->add('phone', TextType::class, [
                'constraints' => new Constraints\NotBlank(),
                'label'       => 'Phone',
            ])
            ->add('email', EmailType::class, [
                'constraints' => new Constraints\Email(),
                'label'       => 'Email',
            ])
            ->add('message', TextareaType::class, [
                'constraints' => new Constraints\NotBlank(),
                'label'       => 'Message',
            ])
            ->add('conditions', CheckboxType::class, [
                'mapped' => false,
            ]);
    }
}

add_filter('wp_symfony_form_wrappers', function($formWrappers) {
    $formWrappers->add(
        new FormWrapper(
            'contact',
            'Fully/Qualified/Namespace/ContactType'
        )
    );
});


TwigBridge::addExtension($twig);

// if you want to customize the form theme
TwigBridge::addExtension($twig, 'component/form.twig');

\Timber\Timber::$locations = [
    (...)
    ABSPATH . '../vendor/symfony/twig-bridge/Resources/views/Form/',
];
js
    WPSymfonyForm.onSuccess(function ($form) {
      if ($form.hasClass('form--contact')) {
        // ANYTHING YOU WANT TO DO 
      }
      $form.find('.form__footer').html('<p>Form successfully submitted</p>');
    });