If I upload a file with YII and another rule fails, then the user has to pick the file again. What is the easiest way to avoid this?
For example, I have a rule that the title must be 20 characters at most. The user types in 21 letters. He chooses a file to upload. When the user is returned to the page, the file is no longer there and he must choose it again, and effectively upload it again. This is very frustrating, especially now when the user will be required to upload up to ten files.
I know Drupal works like this. If you upload and other rules fail, the files appear as screenshots when you return to the form. How can I get the same functionality on YII?
UPDATE If I could get that requirement covered with this extension and not require that the user presses start upload, I would be home free
The original plugin that xupload wraps, there is an additional callback option you could use: .done()
.
In the xupload wiki, the way to access those additional options would be this way:
<?php
$this->widget('xupload.XUpload', array(
// ... other attributes
'options' => array(
//This is the submit callback that will gather
//the additional data corresponding to the current file
'submit' => "js:function (e, data) {
var inputs = data.context.find(':input');
data.formData = inputs.serializeArray();
return true;
}"
),
));
?>
Source
You could probably just change the submit part to done
, and let that save the URL/path of the uploaded file to a temporary hidden field, and move your validation to that hidden field instead, so the user does not have to re-upload a file again.
I moved away from this plugin to the coco uploader as it was easier to implement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With