Yii 1.1: jformvalidate

Javascript Form Validation

JFormValidate is a Yii extension dedicated to provide Javascript Form Validation feature, for the Yii framework. This extension relies on an existing JQuery plugin that provides all the logic and functionnalities for the actual Form validation. JFormValidate uses rules defined by the model, turn them into JS rules compliant with the JQuery plugin. Please refer to the enclosed README.html file for a complete description.

Since Yii 1.1.7, client-side validation has been added to the core CActiveForm Widget, so if you're using version 1.1.7 (or more) of Yii you don't need to use this extension to enable client-side validation.




  • Yii 1.1.x (or previous versions) - please note that this extension does not support Yii 1.0 branch. If you're using the 1.0.xx branch, download JFormValidate v


This release includes both the extension itself, and a set of sample controller/views dedicated to illustrate JFormValidate usage.

  • Extract the release file under a temporary folder
  • copy the extensions folder into your app extension folder

Please refer to the enclosed README.html file for a complete description.


See the following code example from a sample view file.

// initialize form validation.  
echo EHtml::beginForm();
// you may now buid your form. Note that call to CHtml helpers
// methods are replaced by the ones provided by the extension
<div class="simple">
    <?php echo CHtml::activeLabelEx($model,'username'); ?>
    <?php echo EHtml::activeTextField($model,'username') ?>
// at the end of the form, call endForm()
echo EHtml::endForm(); 

And that's it ! ... you form will now be validated on the client browser, based on the rules defined by the Yii model (and supported by this extension).

Please note that since version 1.1.0, this extension can only be used with the EHtml helper class (and not as an application component anymore).

Change Log

February 14, 2010

  • version 1.1.0 - Yii 1.1 support
    • no need to call EHtml::setScenario as scenario is get directly from the model
    • reduce dependencies between the EJFValidate component and CHtml Yii helper class. Note that CHtml::activeName(), CHtml::activeId, CHtml::encode and CHtml::normalizeUrl are still directly called by the extension, but all other calls have been moved to EHtml. It is not possible anymore to directly use the underlying application component, EHtml must be used instead.

December 6, 2009

  • version 1.0.9
    • fix : now the require validator has same behaviour on server and client side, for checkboxes. To validate that a checkbox is checked or not, user should used 'compare' with 'compareValue' set to 1 or true (checked), 0 or false for unchecked ( mh469).
    • fix : when the form is submited, a checkbox with no rule remains with its normalized names. This is because name restoration occurs in the JQuery Validate onSubmit Handler. Fix = name is normalized only when a JS rule is actually defined fot the attribute ( mh469).
    • enh : is a regexp can't be evaluated on client side, match rule returns 'true', so JS form validation can continue. The regexp will be tested by server-side only ( mh469).
    • fix : when using ajaxSubmitButton, url parameters was ignored (makro)
    • enh : added support for parameter 'requiredValue' for the 'required' validator (since yii 1.0.10).
    • clean up form samples.

November 7, 2009

  • version 1.0.8
    • add : added the 'match' validator (regular expression) - added form15 to the sample App
    • update : original jquery.validate.js file was modified in order to make it compliant with JS compressors. In particular, opening and closing braces were added to single 'if' statement (thanks to scythah).
    • update : getCurrentFormId() is now public

August 29, 2009

  • version 1.0.7
    • fixed : js validation rules are not correctly applied when scenario is used (thanks to Jaime)
    • fixed : EHtml::setScenario() and EJFValiudate->setScenario() now forward new scenario to CHtml::scenario (thanks to mindeh)
    • update : modify form11 so onfocusout and onkeyup are active

June 14, 2009

  • version 1.0.6
    • update : sample App (add form13 to illustrate how to create new validators on both client and server side).
    • update : now EHtml::endForm() and EJFValidate.endForm() always return tag . Consequently all forms should be updated and closing form tag removed.
    • update : add EJFValidate.beginForm()
    • new : ajax submit suport - EHtml::ajaxSubmitButton method wraps CHtml::ajaxSubmitButton and supports all its functionnalities
    • update : jquery.jfvalidate.helper.js is updated so when a form needs to be normalized, function $.fn.EJFValidate.uniqueName() is invoked on ajax request completed.

April 16, 2009

  • version 1.0.5
    • fix : call to methode_exists() (line 262)
    • fix : Undefined index: notInt (line 369) In mode error_reporting(E_ALL) these two warning were raised (thanks to letscode)

April 14, 2009

  • version 1.0.4
    • add class EHtml to wrap CHtml (simply extension usage) - replace CHtml:: with EHtml:: to enable client side validation. Note that a call to EHtml::endForm() does include the form closing element.
    • fix case sensitivity errors in the sample form app md5 : e4121e4eaa30f30fd41677207b62fd97

March 21, 2009

  • version 1.0.3

    New feature

    • add support for the allowEmpty attribute attached to Yii built-in validators (sample form10)


    • rename to lowercase sample demo controller and view folder to avoid case issue. rename nav-bar.php to navbar.php

IN ORDER TO USE SAMPLE, PLEASE MODIFY views/jsvform/navbar.php AND RENAME ROUTE TO Jsvform/TestForm (if you're using Windows plateform; no need to do that. Next release will correct this case error)

March 19, 2009

  • version 1.0.2

    New feature

    • Add support for the NUMERICAL built-in Yii validator. All options are supported (integerOnly, min, max, tooBig, tooSmall).
    • add form9 to sample forms. This form illustrate the usage of the numerical validator.


    • replace jquery.validate.pack.js with jquery.validate.min.js because of problems under IE6 that result in the javascript validation to not occur.
    • when no rule can be applied on the client side, the JQuery Validate Plugin initialisation failed, causing a Javascript error to be raised.
    • error message selection for rule compare
    • remove message JS initialisation option if empty.

March 14, 2009

  • version 1.0.1 : Initial release.

Total 9 comments

#3191 report it
burt at 2011/03/24 10:39pm


#1998 report it
Nagash at 2010/10/28 08:42am
problem with CCaptcha

Hi. if on page used this extension and Ccpapthca widget, then refresh button don't work. if I change jquery method delegate() with live() for refresh button - work fine.

#534 report it
phpdevmd at 2010/05/01 07:30am
Great Work!!!
#692 report it
Raoul at 2010/03/17 02:47pm

Hi corpix,

could you please post your problem in the forum (http://www.yiiframework.com/forum/index.php?/topic/1014-extension-javascript-form-validation/)


#703 report it
corpix at 2010/03/15 10:01pm
Some bugs

Hello. Then i use compare for my password inputs and fill form correctly plugin shows error... "Passwords must be repeated exactly" Only then i refill password input(not password_repeat) error disappears

p.s. sorry for my english...thats foreign language for me

#890 report it
vassy at 2010/02/10 11:39am
great stuff

No bugs for me too. I use CForm builder everywhere, so I just had to extend it so it uses EHtml instead of CHtml everywhere and -voila!- it works perfectly for me with Yii 1.1

Thank you.

#1219 report it
scythah at 2009/10/21 10:31am

I did have to run the JS files through JSLint though to find the missing/extra ;s and to add {} around the if statements so that I could use a JS compressor.

Excellent work though!

#1478 report it
serbanc at 2009/07/23 09:17am
really nice

and usefull extension.

one suggestion: add a public function normalizeUrl($url) { return CHtml::normalizeUrl($url); }

it's required when specifying 'url' for ajax.

Regards, Serban

#1737 report it
imortis at 2009/04/23 02:40pm
What i was waiting for

No bugs in my application yet and what can I say - it saved a lot of my time. Thanks a bunch and keep on a good work!

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: Raoul
  • Category: Validation
  • Votes: +17
  • Downloaded: 5,562 times
  • Created on: Mar 14, 2009
  • Last updated: Mar 28, 2011