When I try to create a file upload field following the code in the InputDemo.php file, it does not work for me. Somehow, the input from the file and file_managed elements do not make it into the submission handler.
After double-checking if I copied everything I needed over, and going insane for a while, I decided to check the original example.
Same thing occurs there.
File elements do not carry over their values to the submission handler.

Steps to reproduce

  • Put a breakpoint (or call kint()) on line 308 in InputDemo.php
  • Visit examples/form-api-example/input-demo
  • Fill out the File and Managed file inputs and some others of your choosing
  • Submit
  • View the content of $values; all other element values show up, but not the value for the file inputs

screenshot

CommentFileSizeAuthor
Selection_146.png35.82 KBfirfin

Comments

firfin created an issue. See original summary.

firfin’s picture

Category: Bug report » Support request
Priority: Major » Normal

It seems the managed_file element do get passed to the submit function after all. Can't seem to do anything with the file elements though. Probably somethign missing in my understanding. Changing issue metadata accordingly.

jasonawant’s picture

Title: File elements not passed to submitForm » How to file_get_contents() of unmanaged uploaded file from file form element

Hi!

I recently came across this issue as well.

I've updated the issue title to help improve SEO as I didn't come across this issue in my search results. Fill free to tweak it.

Below are the link URLs I did discover.

https://www.drupal.org/node/2988700
https://drupal.stackexchange.com/questions/228925/get-contents-of-tempor...
https://drupal.stackexchange.com/questions/287668/unable-to-retrieve-upl...
https://drupal.stackexchange.com/questions/239700/how-to-upload-file-in-...
https://www.drupal.org/node/2844730
_file_save_upload_from_form()

I think it would be helpful to expand on the InputDemo Form example to include the difference in file and managed_file form elements.

I'm not sure if the below is correct, but I re-implemented _file_save_upload_from_form() b/c it's its docblock states

* @internal
* This function is internal, and may be removed in a minor version release.
* It wraps file_save_upload() to allow correct error handling in forms.
* Contrib and custom code should not call this function, they should use the
* managed file upload widgets in core.

avpaderno’s picture

Component: Form API Example » Code
avpaderno’s picture

Title: How to file_get_contents() of unmanaged uploaded file from file form element » How can I use file_get_contents() for an unmanaged file uploaded from a file form element?
avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

Status: Active » Fixed

I am closing this issue, since it is a support request for code the OP wanted to write, for which an answer has been given.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.