I get this error message:

Notice: Undefined index: file in file_ajax_upload() (line 271 of modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of modules/file/file.module

Comments

quicksketch’s picture

Can you describe how you've set up your form with conditional rules? How does the upload field "not work"? Is the value lost? Or does it work but you get these errors?

Finally, this is probably fixed already in new conditionals system in the 4.x branch. We might not see a fix for 7.x-3.x if the new system has fixed this problem (and many others with the old conditionals) already.

tobiasb’s picture

A really simple setup:
* page 1 a textfield
* page 2 a file component, which has a conditional rule e. g. the value of the textfield is "test".
Enter the value on page 1 and then try to upload a file on page2, which does not work.
Empty the conditional rule, upload works fine.

michellezeedru’s picture

I can verify that I'm seeing the same errors. My conditional rules are on the page break however, not the file field (i.e. I want this page skipped altogether based on answers on a previous field). When this is the case, I see the file field initially and can select a file for upload. The file uploads, but when the upload is complete, the field disappears off the screen. If I proceed to save, none of the data I entered in other fields on this page is not saved.

If I remove the conditions on the page break, the filefield works as expected.

When I check the recent longs, it seems these 3 errors occur each time this happens:

Notice: Undefined offset: 2 in webform_client_form() (line 1992 of /home/michell3/public_html/sites/all/modules/webform/webform.module).
Notice: Undefined index: guest_photo in file_ajax_upload() (line 271 of /home/michell3/public_html/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /home/michell3/public_html/modules/file/file.module).

jrichards1982’s picture

I am experiencing the same issue. Page two display is a conditional of data on page one. These are the errors:

Notice: Undefined offset: 2 in webform_client_form() (line 1992 of /var/www/html/sites/all/modules/webform/webform.module).
Notice: Undefined index: testfile in file_ajax_upload() (line 265 of /var/www/html/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 274 of /var/www/html/modules/file/file.module).

valderama’s picture

same problem here :/

edit: updating to webform 3.x dev and webform_conditional 1.x dev did _not_ help.
edit2: updating to webform 4.0 alpha did not help either.
edit3:

I guess the problem is that form_state['values']['submitted'] does not contain any data about data other then the upload field (which triggers a form rebuild).

Then, when the form is rebuilt, webform module cannot trigger the conditional correctly, as the data is missing.

valderama’s picture

I solved the problem by using $form_state['storage'] to override $form_state['values'] in the rule checking function:

/**
 * Check if a component should be displayed on the current page.
 */
function _webform_client_form_rule_check($node, $component, $page_num, $form_state = NULL, $submission = NULL) {
  $conditional_values = isset($component['extra']['conditional_values']) ? $component['extra']['conditional_values'] : NULL;
  $conditional_component = isset($component['extra']['conditional_component']) && isset($node->webform['components'][$component['extra']['conditional_component']]) ? $node->webform['components'][$component['extra']['conditional_component']] : NULL;
  $conditional_cid = $conditional_component['cid'];
  
  //these three lines fix the bug! <------------------------------
  if (isset($form_state['storage']['submitted'])){
    $form_state['values']['submitted'] = $form_state['storage']['submitted'];
  } 

valderama’s picture

Status: Active » Needs review
StatusFileSize
new855 bytes

Here is a patch against 7.x-3.x - I assume the crucial parts are the same as in 3.18, which is the version which I am working with.

Please review, thanks!

Walter

valderama’s picture

StatusFileSize
new855 bytes

wrong naming of the patch file. Does not matter much, I guess. However, here is a new patch.

matglas86’s picture

This patch is working correctly. Helped us out with a client.

michellezeedru’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed, the patch in #8 resolved my issue in #3. Thank you!

michellezeedru’s picture

EDIT (sorry for the initial sloppy and incorrect post):

I just updated to webform 7.x-4.0-alpha6, and I'm seeing the same error I reported in #3. By manually adding the patch in #8 the problem is resolved.

historysa’s picture

I have the same issue occuring for webform 7.x-4.0-alpha6 (getting the notices at the top of this post). I manually inserted the patch, yet the issue still occurs. I copied the missing lines into the module starting from the declaration of $conditional_component to the end of the if statement.

Is there something different that michellezeedru may have done?

quicksketch’s picture

This patch makes me very nervous, considering it changes one of the most central parts of Webform's processing code. Any more confirmations of this problem and the patch's solution would be welcome as people try this out. I'm a little hesitant about including it specifically for the 3.x branch, if the only impact is on users of Webform Conditional module.

tobiasb’s picture

What is in $form_state['values']['submitted'] at the moment?

quicksketch’s picture

What is in $form_state['values']['submitted'] at the moment?

It should be the values from the current page that is being submitted. $form_state['storage']['submitted'] should be the values from all pages merged together. We do some extensive manipulation around these values I believe, so just replacing one whole chunk of values with another manipulated set makes me nervous.

jastraat’s picture

I'm seeing this same error with just using the conditionals included in the Webform 3.x branch - not the Webform Conditional module.

jastraat’s picture

I wouldn't suppose this is related?
https://drupal.org/node/1336212

liam morland’s picture

Seems to be a duplicate of this: #1794862: Uploading Files Produces Ajax Error. I put simple steps to reproduce the problem in that issue.

I am seeing this problem and am not using the Webform Conditionals module.

liam morland’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev
vinmassaro’s picture

Status: Reviewed & tested by the community » Needs work

Setting this back to 'Needs work'. We are seeing the problem with 7.x-4.0-alpha9. This particular webform uses conditionals and the patch in #8 doesn't fix the error when uploading an image to a file component.

spadxiii’s picture

Issue summary: View changes
StatusFileSize
new913 bytes

I just updated to latest beta2 (2014-02-12) and can confirm that this issue is still there.

My test is a webform with the following components:
- select options with 2 values
- page break
- file upload
- textarea

Add conditions that shows the file upload for the first select option and the textarea for the second option.

After selecting the first option, submitting to the next page and then clicking the upload button, the file input disappears. This happens because of the conditional removing the field, because the value is not in the $input_values. By also using the form_state 'storage' values, the conditional finds the correct value and does not remove the file input.

Attached a patch with the code I used to fix the issue.

quicksketch’s picture

Status: Needs work » Fixed

Thanks @SpadXIII! This looks much less likely to cause significant problems, and it's a lot easier to understand what's going on with a smaller scoped variable.

I can't see any problems with this patch or approach. In testing it functions as expected and all the tests are still passing. Let's try it out in a wider audience in the next beta release that I'm rolling today to fix other issues found in beta2.

Status: Fixed » Closed (fixed)

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

fenstrat’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Assigned: Unassigned » fenstrat
Status: Closed (fixed) » Patch (to be ported)

Needs porting to 8.x-4.x.

  • Commit bcbec75 on 8.x-4.x authored by SpadXIII, committed by fenstrat:
    Issue #1789040 by SpadXIII: File upload does not work with conditional...
fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Assigned: fenstrat » Unassigned
Status: Patch (to be ported) » Fixed

Committed and pushed a072683 to 8.x-4.x. Thanks!

Status: Fixed » Closed (fixed)

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

john_b’s picture

Version: 7.x-4.x-dev » 7.x-3.22
Issue summary: View changes
Status: Closed (fixed) » Active
fenstrat’s picture

Version: 7.x-3.22 » 7.x-3.x-dev
Assigned: Unassigned » torotil
Issue summary: View changes

@John_B please don't blindly overwrite the OP. That is what the comment field is for.

For reference here is what was posted:

Please commit the patch in #8 to 7.x-3.x - it would have saved me debugging time, and may help others :-)

7.x-3.x is receiving bug fixes only, as this is a bug I'm assigning to @torotil as the 7.x-3.x branch maintainer.

danchadwick’s picture

Category: Bug report » Task

Thanks fenstrat. To clarify, the 7.x-3.x branch has a commitment to receive critical bug fixes, plus whatever bugs torotil sees fit to commit. Therefore this is now a task.

Upgrading to 7.x-4.x is always preferred, whenever possible.

john_b’s picture

Sorry, I must have been tired,

torotil’s picture

@John_B: I'm happy to look into this at one point. But I think that #8 is not the way to go: As stated in #13 replacing $form_state['values']['submitted'] with $form_state['storage']['submitted'] might have side-effects that need to be thoroughly checked. Also there might be webform-based modules that rely on the current way those variables are handled. Thus I much prefer a more cautious patch.

danchadwick’s picture

Status: Active » Closed (won't fix)

Putting this back to won't fix, since torotil isn't actively working on this. All 7.x-3.x non-critical bug fixes are at torotil's discretion.