WP Manifestindependent plugin directory
manifest / developer / wpsymfonyform

WP Symfony Form WP Registry grade A. No security issues foundWP RegistryNo security issues foundOpen the reportA

WordPress plugin to allow using Symfony form component with ease.

★ 0stars
1.1kcomposer installs
v0.4.1latest · 10 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/lin3s/wpsymfonyform/archive/refs/heads/master.zip

On Packagist as lin3s/wp-symfony-form:

composer require lin3s/wp-symfony-form
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

WP Symfony Form

WordPress plugin to allow using Symfony form component with ease

SensioLabsInsight Total Downloads      Latest Stable Version Latest Unstable Version

Installation

If you are using composer run the following command:

$ composer require lin3s/wp-symfony-form

If your composer.json is properly set up you should find this package in plugins folder

Usage

First of all, enable this plugin in the WordPress admin panel.

To create your first form extend as usual from the AbstractType class provided by Symfony component.

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,
            ]);
    }
}

To enable the Ajax calls for this form you need to subscribe to the wp_symfony_form_wrappers WordPress hook.

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

Rendering the form

In case you want to use Twig for rendering a Bridge is provided, just run the following code line passing Twig instance


TwigBridge::addExtension($twig);

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

component/form.twig is your custom form theme that will be used to render the forms. Check the docs about form customization for further info.

Timber In case you are using Timber you should use twig_apply_filters hook. Also, you have to load the form base views inside Timber global locations variable:

\Timber\Timber::$locations = [
    (...)
    ABSPATH . '../vendor/symfony/twig-bridge/Resources/views/Form/',
];

Important Submit event is binded to every element with .form class. In case you need to change it just do the following:

WPSymfonyForm.formSelector = '.your-selector';

Also error container for each form item can be changed using WPSymfonyForm.formErrorsSelector.

The FormWrapper

The FormWrapper is a class designed to contain a form and all its related actions. As you've seen above a new instance is created for each form you want to use in your WordPress project, and need to be registered inside the FormWrapperRegistry.

As first parameter it receives the fully qualified namespace and as second parameter it receives an array of classes implementing Action interface.

Actions on success

In case you need to perform any server side actions, it's as easy as to implement execute method of Action interface. A form instance will to be used as desired. Check src/Action folder to check already implemented actions.

To bind this action to a specific form you need to add it in the FormWrapper.

For client side success actions you can add your callback using the global WPSymfonyForm namespace as follows:

    WPSymfonyForm.onSuccess(function ($form) {
      if ($form.hasClass('form--contact')) {
        // ANYTHING YOU WANT TO DO 
      }
      $form.find('.form__footer').html('<p>Form successfully submitted</p>');
    });

onSuccess() and onError() are available to hook into the form.

Releases

5 releases.

Tag
Published
v0.4.1 latest
Jul 22, 2016 10 years ago
Jun 3, 2016 10 years ago
Apr 27, 2016 10 years ago
Mar 28, 2016 10 years ago
Mar 23, 2016 10 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.

A grade

Security

WP Symfony Form 0.4.0 · audited by WP Registry

No security issues found.

Audited release
0.4.0
Findings
none
Worst severity
—
Content hash
ace0100a83b77631c6b79e41…

WP Registry hashes the installable build and reports on that exact bytes-for-bytes copy. Embargoed findings are withheld until they are disclosed, so a clean verdict means nothing public is outstanding. WP Manifest does not audit code itself.