2017 © Pedro Peláez
 

symfony-bundle form-validation

Let's take the form validation logic and apply it for js, other php scripts, an API...

image

bic/form-validation

Let's take the form validation logic and apply it for js, other php scripts, an API...

  • Wednesday, August 6, 2014
  • by bichotll
  • Repository
  • 1 Watchers
  • 4 Stars
  • 386 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

FormValidationBundle

The objective of this bundle is to create a abstract and generic object of the form information to parse it to another tools (Javascript or maybe PHP tools)., (*1)

For instance: It can help you to addapt this information to javascript validation logic for the forms., (*2)

Dependencies

Check composer.json of the current version., (*3)

Instalation

Composer

composer require bic/form-validation

Enable the bundle

//...
new Bic\FormValidationBundle\BicFormValidationBundle()
//...

How it works

Create the form

        // form Data models
        $formData = array(
            new Form\Model\Register(),
            new Form\Model\Document()
        );

        // form builder
        $formBuilder = $this->container
                ->get('form.factory')
                ->createNamedBuilder('form', 'form', $formData)
                ->add('phone', 'text')
                ->add('password', 'password')
                ->add('document', new Form\Type\DocumentType())
                ->add('submit', 'submit');

        // get form from form builder
        // (http://www.interesarte.com/wp-content/uploads/2013/05/willsmith.jpg)
        $form = $formBuilder
                ->getForm()
                ->handleRequest($request);

Extract the validation

        $formValidation = $this->get('bic_form_validation.form_validation');
        //returns FormValidation object
        $formValidation->extractValidation($form);
        //returns fields array
        $formValidation->getFields();
        //returns json object
        $formJson = $formValidation->toJson();

Return it to the view

        return array(
            //...
            'form_validation' => $formJson,
            //...
        );

And do whatever you want with it., (*4)

json form example

[
    {
        constraints: [ 
            "Default": [
                {
                    "message": "This value should not be null.",
                    "groups": [
                        "Default",
                        "Model"
                    ],
                    "class": "Symfony\\Component\\Validator\\Constraints\\NotNull"
                }
            ]
        ],
        dataClass: "Bic\Voucher\EntityBundle\Entity\Category",
        options: {
            choices: {
                m: "Male",
                f: "Female"
            },
            required: false,
            empty_value: "Choose your gender",
            empty_data: null
        },
        value: '',
        pathName: [
            "name",
            "bic_voucher_entitybundle_category"
        ],
        fullPathName: "bic_voucher_entitybundle_category[name]",
        type: "choice",
        validationGroups: [ ]
    },
    {
    constraints: [ ],
        dataClass: "Bic\Voucher\EntityBundle\Entity\Category",
        options: {
            required: false
        },
        value: '',
        pathName: [
            "miniDescription",
            "bic_voucher_entitybundle_category"
        ],
        fullPathName: "bic_voucher_entitybundle_category[miniDescription]",
        type: "textarea",
        validationGroups: [ ]
    }
]

Full example, (*5)

Last changes

  • Added entity results from the FormView object (dataEntityChoice property)
  • Added JMS Serializer as dependency to get the entity type value and parse it to json
  • Added value property. It has the value of the field.
  • Removed the possibility to get the class name from the data passed
  • Provide better and complete json example (from TODO)
  • Create associated js parsers like ParsleyJs and js form generator script. (Out of project) (from TODO)
  • FIXED - Does not work with complex forms. (from Known errors)
  • More unit testing (from TODO)
  • General info of form added
  • Created first unit testing to check the bundle is working with complex forms
  • Fix known errors (from TODO)
  • Parent forms not avoided
  • Submit buttons not avoided
  • Added more form information
  • Removed jQValidation generator
  • Removed generator folder and strategy. Now the parsers will be aplied externally.

Js form creator

It creates the form from the json information. https://github.com/bichotll/Symfony-FormValidationBundle-js-parser, (*6)

Js ParsleyJS parser

It applies the ParsleyJS validation from the Symfony-FormValidationBundle-js-parser form object or existing one using FormValidationBundle object https://github.com/bichotll/Symfony-FormValidationBundle-ParsleyJS-parser, (*7)

Wiki

How to test it Full example, (*8)

TODO

  • Proper unit test. Until the next change I will not check the responses programatically.
  • Unit test using a mock of container, etc.
  • Test entity type.

The Versions

06/08 2014

dev-master

9999999-dev https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

06/08 2014

1.3.3

1.3.3.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

01/08 2014

1.3.2

1.3.2.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

01/08 2014

1.3.1

1.3.1.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

01/08 2014

1.3.0

1.3.0.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

22/07 2014

1.2.0

1.2.0.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

01/07 2014

1.1.0

1.1.0.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

01/07 2014

1.0.0

1.0.0.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for js, other php scripts, an API...

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation

27/06 2014

0.9.0

0.9.0.0 https://github.com/bichotll/FormValidationBundle

Let's take the form validation logic and apply it for example...javascript. There is an option for jQ Validation. Feel free to apply your logic or extend it.

  Sources   Download

MIT

The Requires

 

twig form validation javascript form validation