CActiveForm aims to provide a simple way of performing client-side model validation via AJAX. Using this widget, you can exploit your validation rules defined in the model class without writing any js validation code. Its usage is very simple, mostly similar to CHtml.
Would you please help me to test this widget in various settings? Your feedback and suggestions are welcome!
Note, CActiveForm will be available in 1.1.1 release.
Below are some code snippets. For more details, please refer to the API documentation of CActiveForm.
Is there a special submit button required? I tried to modify the standard contact form from a generated webapp. It always submits the form as usual, no ajax request is made.
Sadly, the CActiveForm does not validate a selectbox yet.
2.) After entering some value into an TextField the Ajax Request already gets performed. This is annoying, cause after every <TAB> or click he moves the textfield down and opens the error-div. Maybe one should configure an (optional) success-div that occurs when something is done right. (Like "Thank you, this E-Mail is valid")
Ah, and last but not least:
3.) Will you include the CActiveForm as the default way forms get generated by CRUD? I would vote for yes - and let the CActiveForm automatically fall back to Server-Side validation if Javascript is deactivated.
This should work. Could you describe the procedure you take that this doesn’t work?
Not quite sure if I fully understand you, but you can set ‘successMessage’ in the options of error().
I’m not sure if we should do this by default. As you see, CActiveForm does have some limitations. I’m afraid if we do this by default in crud code, some generated code may not be working out of box. Anyway, I assume you know how to customize crud templates, do you?
Ok, sorry for my English and thanks for your quick reply
1.) Yes, you are right! It works now, it was my mistake.
2.) The successMessage was exactly what i meant, but this awkward behavior is still there without an successMessage. To reproduce the problem, please take a quick look at and enter something (change fields by tab or by click). It’s just a demo site anyway.
After every row he does a Ajax respond with the Value i’ve just entered. This looks awkward without an correct successMessage i think.
I used the exact code from the API example to build this form. Or is this behavior intentionally?
3.) hmm, ok that’s your wise decision. At least we should use the CActiveForm-Widget in the blog demo, so it gets widespread, don’t you think so?
Good widget. Can you make a submit button which will inactive until the whole form will not be valid? P.S Testing the widget, found that in this function is not necessary.
It appears that the form attepmts to submit two times when ajax validation is used, thus duplicating the record. I try to insert a record in an empty table and got this result
CDbException
Description
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'dfxvdstgvvd' for key 'username'INSERT INTO `tbl_user` (`username`, `password`, `status`, `create_time`, `create_ip`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4)
It works as expected when ajax validation is not used.
The form submits multiple times in fact to perform validation. You should only do validation for these requests instead of changing server-side states (including inserting records).