Forums

"File upload" in "Multi-Page" forms doesn't work

manualva 27 Feb, 2014
"File upload" in "Multi-Page" forms doesn't work when the file upload element is in starting pages. It only works in the page with the submit button.

I know how to put it to work in a SINGLE PAGE form; seen youtube tutorials and read some documentation. BUT, just can't get it to work in a multi-page form. I've tested the function in the last page, which is the fourth and the one with the submit button, by adding an dummy upload element and it works fine. However the other upload fields, in page 2 and 3, don't upload anything. Please help!
GreyHead 27 Feb, 2014
Hi manualva,

You need to have the Upload Files action in the page immediately following the one with the File input, You may need more than one Upload Files action if you have File inputs on several pages.

Bob
manualva 27 Feb, 2014
Thanks for your help. That was fast!

They're uploading alright. I can see them in my file manager in their respective upload folder, but I can't see them as email attachments, even though I configured "attachments fields name" field with their respective field names.
GreyHead 27 Feb, 2014
Hi manualva,

OK I think that the attachment problem is that the file name is passed forward to the later pages but not the path information about where they are saved. You'd probably have to sort this out using Custom code. Please see this FAQ which gives you the code to use for a 'static' file, you'd need to update this to use the 'dynamic' names passed forward from the previous steps.

Bob
manualva 28 Feb, 2014
Three questions. Two are simple, one is not so much.

1. This custom code must be placed in each of the "multi-page" pages in my form?

2. Lost you with the 'static' file (is that a custom code element?) and 'dynamic' name (what are those?). I'm using CF3 BTW.

3. I'm sorry greyhead I don't know much about php. I can play with the code around by logic. So what I can see here is that I certainly need the files_array variable and the attach_files variable and the last code
$form->data['file_array'] = $attach_files;
.

However, I'm not using check boxes so I don't know how this code could be adapted to a simple upload file element in a multipage as in my case. And the if element, I really don't think I should use that.

<?php
if ( !isset($form->data['checkboxes']) || count($form->data['checkboxes']) == 0 ) {
  return;
}
$files_array = array (
  1 => JPATH_SITE.'/some_path/some_file.pdf',
  2 => JPATH_SITE.'/some_path/some_other_file.pdf',
  . . .
);
$attach_files = array();
foreach ( $files_array as $k => $v ) {
  if ( in_array($k, $form->data['checkboxes']) ) {
    $attach_files[] = $v;
  }
}
$form->data['file_array'] = $attach_files;
?>


Please help. Thanks!
GreyHead 01 Mar, 2014
Hi manualva,

The code (or a version of it) needs to be on each form event where you are uploading a file (or files). It adds information about the file to the form data so that you can access it later.

In our jargon, a 'static' file is one that is always the same - for example a terms and conditions pdf that you attach to emails; a 'dynamic' file is one that is uploaded by the user, so is different each time.

This does need a bit of PHP experience to add the correct data. I'l try to take a look when I have a bit of time.

Bob
This topic is locked and no more replies can be posted.