The Friendly Web Guys

The Jimmyweb Blog

sfJqueryFormValidationPlugin – A client-side form validation plugin for Symfony

1st
June

2009

Posted by - under Developer 18 Comments

symfony

Jimmyweb is proud to present our first plugin for the Symfony Framework!

The plugin is called sfJqueryFormValidationPlugin (yes it’s a mouthful) and a beta version is available now from the plug-ins section of the Symfony website.

This plugin adds much-needed client-side form validation to sites built with the new(ish) Symfony forms framework. Presently, you can only specify server-side validation rules in a Symfony application – so our plugin parses the server-side rules into a format which can be understood by the jQuery Validation plugin, which in turn utilises the exceptional jQuery javascript library.

This essentially means that you get client-side form validation in your Symfony applications with no additional work whatsoever.

In a recent project, I had to build client side validation manually for a Symfony project with a number of  large forms. The validation alone took two days to build and test. This plugin would have reduced two days of development from this project, had it existed then (in fact this was the catalyst for the production of the plugin in the first place).

This plugin is still in Beta, however we are running it successfully on a couple of production websites so far. We would encourage Symfony developers to give it a try and come back to us with bugs, suggestions, enhancements or comments.

In the future we are looking to add extra features such as accessibility enhancements and features to make forms more attractive.

Tags used in this post:
, , , ,

Share this post:
Share Share Share Share Share

18 Comments

gravatar

webPragmatist says:

October 17th, 2009

Thanks for the plugin! It seems to need some work to support embedded forms. I’ll let you know if I make any progress!

gravatar

James Beattie says:

October 19th, 2009

Hi WebPragmatist,

Thanks for that.

Yes we are aware of the issue with embedded forms and our next release will deal with this. It should be ready in a couple of weeks.

Cheers,

James

gravatar

John822 says:

October 22nd, 2009

Very nice site!

gravatar

Peter says:

February 23rd, 2010

Hi James,

Is this plugin still under active development? There’s no release for 1.3 or 1.4 – have you future plans?

gravatar

James Beattie says:

February 25th, 2010

Hi Peter,

Yes the release for 1.3/1.4 is nearly ready to roll. It’s completely re-engineered and now support embedded forms. I just need to do some more tests before I release it.

You can check out the new version from Symfony’s SVN repo if you absolutely need to start using it now (but still has a few bugs).

Cheers,

James

gravatar

greg0ire says:

September 17th, 2010

Hi James,
I reported a bug here:
http://trac.symfony-project.org/ticket/8965 , did you see it? I’m also having trouble translating error messages for the sfValidatorInteger kind of widget, how do I do that?

gravatar

James Beattie says:

September 18th, 2010

Hi there, both issues will be resolved in the next release (in about a month).

gravatar

TGArtist says:

December 21st, 2010

Is there any way to make it work? :( I’ve followed all steps in the readme file, but nothing happens. I have about 40 forms in my app and the customer asked me to make client side validation too. Thanks for any help!

gravatar

James Beattie says:

January 6th, 2011

Hi there, if you email me support@jimmyweb.net with a few more details, I’ll see if I can sort it out for you.

gravatar

Gregoire says:

January 20th, 2011

Hi,

First, thank you for this plugin! I’m testing it, and I’ve found a bug with post validators:

When you just have a sfValidatorSchemaCompare as post validator, the parsePostValidator() method doesn’t return an array, which is not normal.

So replace this line (line 347):
return “$(‘$right_field’).rules(‘add’, ” . stripslashes(json_encode($rules)) . “);”;

By this one:
return array(“$(‘$right_field’).rules(‘add’, ” . stripslashes(json_encode($rules)) . “);”);

I guess you should also change the line 335:
$return[] = $this->parsePostValidator($form, $v);

By something like this:
$return = array_merge($return, $this->parsePostValidator($form, $v));

But I haven’t tested this second change.

Good luck! :)

gravatar

Gregoire says:

January 20th, 2011

I’ve also noticed a bug with non-latin characters in validator messages, because of the usage of json_encode() function.

So something like “Tést” becomes “Tu00e9st”.

gravatar

Gregoire says:

January 20th, 2011

Sorry for the successive comments, but I’ve found a way to fix the non-latin characters bug:

Just by removing every addslashes() and stripslashes() calls of sfJqueryFormValidationRules.class.php

I haven’t noticed any side effect for the moment…

gravatar

James Beattie says:

February 4th, 2011

Thanks Gregoire, I will incorporate these fixes into the next release.

gravatar

Gregoire says:

February 21st, 2011

Thank you for your update.

I’ve also noticed a small point: I suggest you to use jQuery in compatibility mode, I mean you should always use jQuery(…) method instead of $(…) shortcut. This way, your plugin can easily be used on a website that includes both jQuery and prototype for example.

gravatar

James Beattie says:

February 23rd, 2011

Hi Gregoire,

I am actually using jQuery as stated. If you notice the enclosure, it is formed like this:

jQuery(function($){
// $ is only referenced to jQuery within this enclosure
});

Cheers,

James

gravatar

Gregoire says:

February 25th, 2011

Oh you’re right, I didn’t know about that!

gravatar

Boris says:

July 15th, 2011

Hi,
I’m installed this plugin, but
have a few problem, I need submit my form with a link like this:

Save

Anybody can give me any help ?!

Thanks

gravatar

James Beattie says:

July 16th, 2011

Hi Boris,

It is not good practice to use hyperlinks to submit forms.

If you really need something that looks like a link rather than a button, you can do something like this:

Cheers,

James

Leave a Comment