craft-preparse-field
craft-preparse-field copied to clipboard
Files uploaded in front-end entry form are lost
Hi! Thanks for your great work on Preparse. I think this issue is related to #23 and #52.
Starting in 1.0.7, files uploaded as part of a front-end entry form aren't working for us, with Craft 3.1->3.3. The entry is getting saved properly but the file is disappearing. I tracked this down to the resetUploads()
method in PreparseField.php.
I know you changed it from unset($_FILES);
to $_FILES = [];
to fix some issues, but that's still a problem for us because the file is getting lost. I hacked a fix for it for now (by adding a hidden field to our entry form and then returning early from resetUploads()
if it's present) but I know that's not a permanent fix if we upgrade in the future.
Do you have any ideas on other fixes for this?
Thanks!
@mrw Mind sharing your temp fix for this?
@sjcallender yes, in preparse-field/src/PreparseField.php
we added this to the top of resetUploads()
(you can fork it then reference your own fork in composer):
if (!empty($_POST['is_fe_upload_form']) && $_POST['is_fe_upload_form'] == 'yes') {
return;
}
Then in our front-end form we added this:
<input type="hidden" name="is_fe_upload_form" value="yes">
It's not great but it works!
Thanks @mrw!
Hey @aelvan, has this behavior ever been resolved?
Er, sorry, @aelvan, i have no idea why i tagged you. Should've been @jalendport!
I just discovered the same issue. However, only with uploading new user photos in front-end user profile forms as per https://craftcms.com/knowledge-base/front-end-user-accounts#user-profile-form. In preparse-field/src/PreparseField.php
, I did the following based on comment above https://github.com/besteadfast/craft-preparse-field/issues/57#issue-490492389, and that seems to have resolved the issue. Preparse 1.2.5 on Craft 3.7.18.2
private function resetUploads()
{
// $_FILES = [];
unset($_FILES);
// UploadedFile::reset();
}
Also seeing this behaviour, exactly as @ademers describes it. Craft 3.7.37, Preparse 1.4.0.
I have a fork setup if it helps anyone. Add the following to your composer.json
file:
"config": {
...
},
"repositories": [
{
"type": "git",
"url": "https://github.com/engram-design/craft-preparse-field"
}
],
Then run composer require besteadfast/craft-preparse-field:dev-craft3
.
This still seems to be an issue in CraftCMS 4.6.0 and Preparse 2.0.2.