Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files uploaded in front-end entry form are lost #57

Open
mrw opened this issue Sep 6, 2019 · 8 comments
Open

Files uploaded in front-end entry form are lost #57

mrw opened this issue Sep 6, 2019 · 8 comments

Comments

@mrw
Copy link

mrw commented Sep 6, 2019

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!

@sjcallender
Copy link

@mrw Mind sharing your temp fix for this?

@mrw
Copy link
Author

mrw commented Dec 11, 2019

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

@sjcallender
Copy link

Thanks @mrw!

@adrienne
Copy link

Hey @aelvan, has this behavior ever been resolved?

@adrienne
Copy link

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

@ademers
Copy link

ademers commented Nov 5, 2021

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 #57 (comment), 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();
  }

@engram-design
Copy link

engram-design commented Sep 8, 2022

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.

@leevigraham
Copy link

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

AyupMike added a commit to AyupMike/craft-preparse that referenced this issue Sep 25, 2024
Fix for frontend image uploads issue as per jalendport#57 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants