acseo / form-js-validation-bundle
Symfony Form Js Validation Bundle
Installs: 50 064
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 1
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=5.3.2
- symfony/symfony: >=3.0.0
This package is auto-updated.
Last update: 2024-11-29 05:20:58 UTC
README
A bundle that add js validation to you forms
Installation
- Install using composer
composer require acseo/form-js-validation-bundle
- Update AppKernel.php :
<?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new ACSEO\Bundle\FormJsValidationBundle\ACSEOFormJsValidationBundle(), // ...
- Select your js validation plugin between validation.io and jqueryvalidation.org in the parameters.yml :
// app/config/parameters.yml
parameters:
// ...
// to use the validation.io
acseo_form_js_validation.service: acseo_form_js_validation_io
// or to use the jqueryvalidation.org
acseo_form_js_validation.service: acseo_form_jquery_form_validator
Usage
Add Form validation to your form
In your controller, add js form validation :
<?php //... public function newAction(Request $request) { // ... $awesomeEntity = new AwesomeEntity(); $form = $this->createForm(AwesomeEntityType::class, $awesomeEntity,array( 'action' => $this->generateUrl('awesomeentity_new'), 'method' => 'POST') ); // ... $form = $this->get("acseo_form_js_validation.service")->addJsValidation($form); // ...
Update templates
Using form validation.io
-
In your base template, use formvalidation js and css : http://formvalidation.io/getting-started/#usage
-
In the template when the form is used, just update the code with this :
<!-- new.html.twig --> {{ form_start(form, {'attr': { 'id' : 'awesome_entity_form', 'data-fv-framework' : 'bootstrap', }}) }} <!-- display your form here --> {{ form_end(form)}} <script type="text/javascript"> $(document).ready(function() { $('#awesome_entity_form').formValidation(); }); </script>
Using form jqueryvalidation.org
-
In your base template, use jqueryvalidation js and css : https://github.com/jquery-validation/jquery-validation/releases
-
In the template when the form is used, just update the code with this :
<!-- new.html.twig --> {{ form_start(form, {'attr': {'id': 'awesome_entity_form'}}) }} <!-- display your form here --> {{ form_end(form)}} <script type="text/javascript"> $(document).ready(function() { $('#awesome_entity_form').validate(); }); </script>