Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate Symfony 2 form on client side (javascript)

I'm new to symfony 2 and i'm trying to build a standard form which should be validated by the server and by the navigator.

Server-side validation works fine with assertions like @Assert\... but i cannot find a way to get this working on client side.

After searching, i pointed out that Symfony 2 does not have a javascript library to manage this..

So my question is : What's the easiest way to do this ?

I know the possibility of using client side library like jQuery Validation plugin or something like Regula, but that would means that i have to duplicate my validations rules..

like image 465
Leto Avatar asked Dec 03 '12 13:12

Leto


People also ask

Can we validate client side form in JavaScript?

JavaScript provides facility to validate the form on the client-side so data processing will be faster than server-side validation. Most of the web developers prefer JavaScript form validation. Through JavaScript, we can validate name, password, email, date, mobile numbers and more fields.

Can JavaScript be used to validate forms?

HTML form validation can be done by JavaScript.

What is form validation in JavaScript?

The Complete Full-Stack JavaScript Course!JavaScript provides a way to validate form's data on the client's computer before sending it to the web server. Form validation generally performs two functions. Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in.

What is form Validator?

Form validation is a “technical process where a web-form checks if the information provided by a user is correct.” The form will either alert the user that they messed up and need to fix something to proceed, or the form will be validated and the user will be able to continue with their registration process.


1 Answers

Symfony is a PHP framework, ie server-side application framework. It doesn't provide client-side validation unless you use HTML5 one with required attribute and other email type for input (that is still not very well implemented in browsers).

So you have to find your own solution and try to plug it in front of Symfony2 to make it as easy as possible... or find an existing bundle like APYJsFormValidationBundle

like image 80
AlterPHP Avatar answered Oct 20 '22 02:10

AlterPHP