[EXTENSION] wvActiveForm

(Rangelspam) #1

wvActiveForm is a CActiveForm descendant that validates the input on client with jQuery, using the rules defined at the model, while also supporting custom rules.



* Required

* Number

* String (length)

* Email

* Default value (displays value that disappear on field click)

* No whitespace


* Manual rules


* jQuery.Validate

* jQuery.Numeric

* jQuery.DefaulValue

* jQuery.keyFilter

CValidator supported:

* CRequiredValidator

* CStringValidator

* CNumberValidator

* CEmailValidator

* CUrlValidator

(Mario Ffranco) #2

Instead of reimplementing all the rules you could use jformvalidate in your extension.

(Rangelspam) #3

Yes I saw it, but to use it one must modify his source code, I wanted a solution that needed no code changes, and uses CActiveForm.

(Manu34) #4

Hi Rangel,

it seems like a promising extension ! however, I tested it following your instructions, and I get the error :

Fatal error: Call to undefined function lcfirst() in H:\home\Project\yii.1.2\protected\extensions\wvactiveform\wvFormRules.php  on line 48



ps: you’re right about jformvalidate not supporting CActiveForm Widget, and I’ve been thinking about releasing a new version that would support CActiveForm Widget…

(Rangelspam) #5

Hmm you’re right, lcfirst function only exists in PHP 5.3+, I’ve released a new version without this call.

About jformvalidate, as I started working with Yii 1.1, all my code was already using CActiveForm, so I want a method of upgrading all my applications with a minimum effort, that’s why I created this extension.

Also, I wanted to make it easy for 3rd party developers create his own rules as extensions, again always thinking of minimum code changes.

(Freezy 88) #6

Hello there! :)

I have some problem with latest wvActiveForm from svn, which reproduced by definition rule with option: ‘allowEmpty’ => false.

For example:

'telephonePresent' => array(



  'min' => 2,

  'max' => 100,

  'allowEmpty' => false,


I think option ‘allowEmpty’ is semantically equals to ‘require’ rule (do you think? :) ), and expected to see on page something like:

'Order[telephone]': {

            'required': true,

            'minlength': 2,

            'maxlength': 100


But there is:

'Order[telephone]': {

            'minlength': 2,

            'maxlength': 100



Possible solution within attachment (maybe we need move $allowEmpty and related processing to base class).

(Rangelspam) #7

Hmm I think the main problem is, Yii doesn’t take allowEmpty in account when checking for required fields (CModel::isAttributeRequired), and also doesn’t add the ‘*’ on the field’s label:

	public function isAttributeRequired($attribute)



		foreach($model->getValidators($attribute) as $validator)


			if($validator instanceof CRequiredValidator)

				return true;


		return false;


This "allowEmpty" conflicts with the required validator, but on the case of a form, the field IS required when allowEmpty is false, so I think your patch is correct.

I added it to the SVN.

(Freezy 88) #8

Hello again! :)

I’ve explored a new bug (or feature :) ). For example, we defined such rule




  'min' => 4,

  'max' => 20,

  'allowEmpty' => false,

  'message' => Yii::t('error', 'Please enter valid {attribute}.'),

  'tooShort' => Yii::t('error', 'Please enter valid {attribute}.'),

  'tooLong' => Yii::t('error', '{attribute} is too long.'),

  'on' => 'update',


The problem is shown, when another language set in config. We see default english-labeled attribute.

To solve the problem, please fix wvActiveForm.php:

public function addValidationForValidator($model, $id, $name, $attributeName, CValidator $validator)


  $attributeName = $model->getAttributeLabel($attributeName); // added

(Rangelspam) #9

Hmm are you sure about this? Are you calling this method directly? Because it is only called in the "checkValidation" method, and it already does this.

	protected function checkValidation($model,$attribute,&$htmlOptions=array(),





		$attributeName = $model->getAttributeLabel($attribute);


		foreach ($model->getValidators($attribute) as $validator)

			$this->addValidationForValidator($htmlOptions['id'], $htmlOptions['name'], $attributeName, $validator);



(Freezy 88) #10

Yeah, it seems i was wrong :) Thanks :)

(Sumwai Low) #11

Does it works with form builder? I tested it with form builder but it doesn’t works out of the box, doesn’t know where to modify though, any ideas?

(Rangelspam) #12

What form builder? If it uses CActiveForm it should work, if it uses CForm, then it won’t.

(Rmrcoxa) #13

When I try to use qtip layout, I got a javascript error.


Error: $(this).data("qtip") is undefined

Source-code: jquery.qtip-1.0.0-rc3-dm.js

Line: 38