Hello,
I have a multistep webform divided in to two steps by a page break. I am using a form alter on step 2 to do some processing on the values returned from step 1. Here is the code I have added after step 1 where I try to count the files that were uploaded in step 1, then present them with a custom textfield to add file titles if needed. Then on submit I assign those file titles to the file names.

Unfortunately the values are not submitted and do not see them on the webform results which seems like the values are lost and not available in the webform submission. Wondering if any one can nudge in the right direction.

I dpm the submission array and do not see those values.

Adding the custom code that I have added for step 2

// Get the form_state to pass on to our build function.
                // Webforms doesn't provide it at this point so we'll need to manually get it using the form's build_id.
                $forminfo = form_get_cache($_POST['form_build_id'], $form_state); 
                dpm($forminfo);
                $multifilesArray = $forminfo['submitted']['attach_presentation_and_or_paper'];
                $first_key = key($forminfo['submitted']['attach_presentation_and_or_paper']);
                $array_keys = array_keys($forminfo['submitted']['attach_presentation_and_or_paper']);

                foreach ($multifilesArray as $key => $value )
                {
                    if (is_string($key))
                    {
                        // delete string keys
                        unset($multifilesArray[$key]);
                    }
                }

                $filesuploaded =(count($multifilesArray)-1);
                for($count =0; $count < $filesuploaded; $count++) {
                    $fid = $multifilesArray[$count]['#default_value'];
                    $fileDetails = file_load($fid);
                    dpm($fileDetails);
                    
                    $form['submitted']['filetitle'][$count] =  array(
                      '#type' => 'textfield', 
                      '#title' => t('Uploaded file name is '.$fileDetails->filename.'. </br>Custom File Name (Optional)'), 
                      '#size' => 60, 
                      '#maxlength' => 128,
                    );
                    
                    //Storing fid as hidden
                    $form['submitted']['fid'][$count] = array('#type' => 'hidden', '#value' => $fid);
                }

                $form['submitted']['filesuploadedCount'] = array('#type' => 'hidden', '#value' => $filesuploaded);
                $form['#submit'][]='xyzcustom_multifile_upload_submit';


/**
 * Multi file upload form submit
 * @param type $form
 * @param type $form_state
 * @return type
 */
function xyzcustom_multifile_upload_submit($form, &$form_state) {
    
    $filesuploadedCount = $form['submitted']['filesuploadedCount']['#value'];

   for($count = 0; $count < $filesuploadedCount; $count++) {
        $fid = $form['submitted']['fid'][$count]['#value']; 
        $fileDetails = file_load($fid);
        $fileTitle = $form['submitted']['filetitle'][$count]['#value'];
        $fileDetails->filename = $fileTitle;
        file_save($fileDetails);
    }
}

My hunch was that unset($multifilesArray[$key]); may be causing to lose the values, so I tried the step 2 without the alter and even then the values are lost, thus wondering if there is anything else with pagebreak that I might be missing.

Happy to add any more information that is needed to make the issue more clear.

Thanks.

Comments

DanChadwick’s picture

Category: Bug report » Support request
Status: Active » Fixed

a) This isn't a bug report. It's a custom programming support question.
b) As is noted in the large STOP notice when you post a new issue, this issue queue doesn't supply custom programming support. There just aren't the resources. Use one of the other resources listed there.
c) Version 4.1? Really? 4.7 is current.

pal4life’s picture

Status: Fixed » Closed (fixed)

Hi,
a)Thanks for that correction, will note for future purposes
c)Unfortunately not my decision in this case for an ongoing project.

For anyone else who stumbles upon this, yes messing with form_state was causing the issue. I was able to leverage other values coming from step 1. I just did a var_dump/dpm and checked the source for values that I was interested in and used those.

Thanks.

DanChadwick’s picture

4.1 contains two security vulnerabilities, since corrected, which means every hacker in the world knows about them.