I’ve tried to disable the javascript but the problem still exist.
But I’ve realised that it is because of the “id” that I set below that affects the validation. I can’t remove the “id” because I need it for the javascript.
In that case, why don’t use the id assigned by Yii in your JS code? In your getElementById(“projectPhoto”), instead of “projectPhoto”, you’d use the “ModelName_projectPhoto” syntax.
Or, if you use your JS inside your PHP, you can use [font=“Courier New”]getElementById("’ . CHtml::activeId($model, ‘projectPhoto’) . '")[/font]
Whether I am setting my own id or not (in htmlOptions), I am getting server side validation done.
But after enabling clientSideValidation in CActiveForm, I am not able to see any sign of errors below file element field. I think this is because currently client side validation is not supported for CFileValidator.
After enabling ajaxValidation with setting my own id , no errors are displayed.
This may be due to yiiactiveform.js only identifying the id set by YII in the form of "ModelClass_attribute"
After enabling ajaxValidation without setting any id myself, Whenever I click the field what I am getting the following
.
When I explored the things in FIREBUG console , nothing is getting posted from my file field.
TestForm[favourite]
TestForm[favourite][] 1
TestForm[favourite][] 2
TestForm[image] //This is always blank irrespective of whether I choose a file or not.
TestForm[married] 0
TestForm[married] 1
TestForm[name] seenivasan
TestForm[spouseName]
ajax test-form
In documentation it is mentioned that the uploaded file information can be obtained via $_FILES.
Then the basic question is whether the files are sent to the server by method POST or not.
If not , then how we are going to validate file inputs through AJAX?
public function rules()
{
return array(
array('project_photo', 'required'),
array('project_photo', 'file', 'allowEmpty'=>false, 'types'=>'jpg,jpeg,gif,png'),
);
}
However, i can only validate whether it is blank field. I can’t validate whether it is an image or not even when I have specified the rules in the model as shown above. Do any of you know why?