Hi everyone,

Currently I am working on a module to allow customers upload files for products with Enable Upload setting on Node form.

Right now working on Checkout Panel to get files, successfully rendered the fields for products.

But on 'process' $op for hook_checkout_pane's callback function, the PHP $_FILES array is receiving only single file from ending field out of the file fields rendered.

Tried all the ways dpm(arg2), dpm($_FILES), print_r($_FILES), all are giving the same output.

Please check the attached views of before and after submit state.

Thanks & Regards,

Tajinder Singh

Comments

tajindersingh’s picture

Title: Custom Checkout Panel Files Missing in $_FILES array » Custom Checkout Panes File Field Files Missing in $_FILES array

Sorry, Changed misspelled title 'Checkout Panel' to 'Checkout Panes'

longwave’s picture

Issue tags: -checkout, -checkout panes

Strange that one file gets through, instead of both or none. What is the name of your file upload field in the HTML? Looks like it's "panes" - are you using the same name for both fields?

longwave’s picture

#83698: $source parameter in file_save_upload() not work as expected when field is in a fieldset with #tree set to TRUE seems relevant.

"You will run into problems if you try to use more than one file field inside a fieldset. In that case the last file field is returned."

tajindersingh’s picture

Hi longwave,

Thanks for the quick hints.

The forms api suggests that file field doesn't support #name property, but it does in this case.

I just set the #name different for both the fields and now it is working fine.

Thanks again,

Tajinder Singh

tajindersingh’s picture

Status: Active » Fixed

marking solved

Status: Fixed » Closed (fixed)

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

juankvillegas’s picture

Thank you TajinderSingh for your suggestion. I used it an it worked.

  $form['tax-certificate'] = array(
    '#type' => 'file',
    '#name' => 'tax-certificate',
    '#title' => t('Tax Exemption Certificate'),
  );

But in my custom pane, when $op == 'process' I added this little code:

  $field = 'tax-certificate';
  foreach ($_FILES as $key => $value) {
    if ($key == $field) {
      foreach ($value as $fkey => $fvalue) {
        $_FILES['files'][$fkey][$field] = $fvalue;
      }
    }
  }
  
  // more code and validations here
  
  $file = file_save_upload($field, $validators, file_directory_path());

This is because file_save_upload will search the file information only in a specific location under $_FILES array.