craft-preparse-field icon indicating copy to clipboard operation
craft-preparse-field copied to clipboard

Files uploaded in front-end entry form are lost

Open mrw opened this issue 4 years ago • 8 comments

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 avatar Sep 06 '19 19:09 mrw

@mrw Mind sharing your temp fix for this?

sjcallender avatar Dec 11 '19 15:12 sjcallender

@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!

mrw avatar Dec 11 '19 16:12 mrw

Thanks @mrw!

sjcallender avatar Dec 11 '19 16:12 sjcallender

Hey @aelvan, has this behavior ever been resolved?

adrienne avatar Jun 25 '21 18:06 adrienne

Er, sorry, @aelvan, i have no idea why i tagged you. Should've been @jalendport!

adrienne avatar Jun 25 '21 18:06 adrienne

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();
  }

ademers avatar Nov 05 '21 16:11 ademers

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.

engram-design avatar Sep 08 '22 01:09 engram-design

This still seems to be an issue in CraftCMS 4.6.0 and Preparse 2.0.2.

leevigraham avatar Jan 12 '24 20:01 leevigraham