I have a view file with this form
echo $this->Form->create('Project', array('enctype' => 'multipart/form-data'));
echo $this->Form->input('subject', array('label' => 'Task Name'));
echo $this->Form->input('Project', array('label' => 'Project Files', 'type' => 'file'));
echo $this->Form->end();
and I have a model which validate subject to be not empty.
If nothing wrong, everything is good. But, if say:
1. I go to the page
2. Click Browse button, and then choose a file
3. forget to fill out subject
4. click submit
It will trigger validation error which say subject should not be empty, but the problem is the file upload field is empty out (due to page refresh I assumed when it submit), so now if the user realize they forget to fill the subject field, they will field it out, and click submit again without realizing that, the file he try to upload has not been upload yet.
How to prevent this from happening? how can I trigger validation but it still keeping the file upload field populate?