Client side validation (CActiveForm,JS, Ajax, trigger/don't trigger validation)

Hi there,

as I’m new to this forum I want to greet the members of this forum! In our company we are planning to re-implement an existing web-application and I want to check if Yii could be a good framework to base our application upon.

Currently I have a problem with the way Yii handles client-side validation. AFAIK yii uses some own js code (based on jquery) which intercepts the submit checks if the values were validated already, validates them if needed and calls the submit again.

So the sequence for the submit (in case the validation succeeds) is something like:

[list=1][]Some generic event like a "button click" issues the submit.[]The submit is intercepted. Because no validation was done before the values are now validated[*]The submit is called again (through a submit button yii hopes to find inside the form if read the code correct, but I do not really understand the chosen implementation) and the data is transferred to the server.[/list]I tried to draw this as a picture: 2340


While the validation works like a charm, I really do miss two features:

  • Call the validation explicitly (without a submit)
  • Call the submit without the validation

The first one would be great for ajax-submits, which do not use the form.submit().

The second one is needed to bypass the validation if needed e.g. for abort buttons.

Some really nice-to-have would be to even choose the scenario on the client side…

For the case, where you want an ajax-submission to be validated before sending, a "solution" is presented in bug #2008 but that is more a walkaround than a solution to me…

Both features seem to be missed by several users of yii as a quick forum search reveals:

So what is the state of these issues? Will they be addressed in the near future or is it more likely that Yii will never provide the requested features?

Any opinions, corrections and suggestions are highly welcome!

Greets acron

Welcome to yii …! we will learn togather …

Check the documentation for CActiveForm…

for both situations you can disable the clientvalidation and leave only the ajax validation (or disable even that one)… this way the validation is done on the server and you can controll it with the validation rules or even use custom validation metods…

Thanks for your answer, mdomba.

I checked the CActiveForm, of course, as well as any document I was able to find about yii and validation. I’m aware of the possibility to do server-side validation through submit and through AJAX, but I think it is not necessary to involve the server for simple validation checks and yii provides client-side validation. The problem is that this is not working with ajax-submit in contrast to a normal html or javascript submit.

To summarize: I think it is a shortcoming of the yii framework to provide client-side validation which does not work with ajax-submit and I’m wondering why there are no plans to resolve this. There are some possible solutions to overcome this problem and the simplest might just be to add a public interface to trigger the validation as requested in this thread.

Greets acron