Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Form Js Validation Bundle Laravel Package

acseo/form-js-validation-bundle

Symfony bundle that adds client-side JavaScript validation to Symfony forms. Choose between formvalidation.io or jqueryvalidation.org, enable the service in parameters.yml, call addJsValidation() in controllers, and initialize validation in your Twig template.

View on GitHub
Deep Wiki
Context7

ACSEO Form JS Validation Bundle

A bundle that add js validation to you forms

Installation

  1. Install using composer
composer require acseo/form-js-validation-bundle
  1. Update AppKernel.php :
<?php
// app/AppKernel.php
class AppKernel extends Kernel
{
	public function registerBundles()
    {
        $bundles = [
        // ...
        new ACSEO\Bundle\FormJsValidationBundle\ACSEOFormJsValidationBundle(),
        // ...
  1. 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

  1. In your base template, use formvalidation js and css : http://formvalidation.io/getting-started/#usage

  2. 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

  1. In your base template, use jqueryvalidation js and css : https://github.com/jquery-validation/jquery-validation/releases

  2. 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>
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator