Hello,

I would like a webform component with "managed_file" form element.

Component edit form:

/**
 * _webform_edit_component()
 */
function _webform_edit_webform_pic($component) {
  $form = array();
  $form['extra']['picture'] = array(
    '#type' => 'managed_file',
    '#title' => t('Image'),
    '#description' => t('Image upload'),
    '#upload_location' => 'public://webform_pic/',
  );
  return $form;
}

But, if file uploaded, then found error message:

Notice: Undefined index: webform_component_edit_form in drupal_retrieve_form() (line 750 of /includes/form.inc).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'webform_component_edit_form' not found or invalid function name in drupal_retrieve_form() (line 785 of /includes/form.inc).
Notice: Undefined index: extra in file_ajax_upload() (line 267 of /modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 276 of /modules/file/file.module).

And not show the uploaded file.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Category: bug » support

Is this a question about how to write a custom component? I don't help with custom coding in the issue queue.

nevergone’s picture

The component full code is attached: webform_pic.module.txt (remove the ".txt" extension)
I think, this is webform bug, because the file_managed_test.module.txt (attached) is works well.

quicksketch’s picture

Status: Active » Closed (won't fix)

As mentioned in the submission guidelines, I don't provide help with custom coding:

Any issues regarding "how do I code ..." or "how do I theme ..." will not be answered. Please look elsewhere for coding resources.

Please refer to other resources such as IRC or Drupal StackExchange to ask your questions.

nevergone’s picture

Okay, but I think, that you don't test the code above.
If you see/test and say: "This is not webform bug", I accept and search another solution.
But I yet think, this is bug webform and managed_file form element, and cause the "Upload" submit button.

nevergone’s picture

Status: Closed (won't fix) » Needs work
FileSize
660 bytes

Patch is included latest Webform 7.x-3.x, test module is here: http://drupal.org/node/1409154#comment-5485196

quicksketch’s picture

Thanks, I think you're correct that this may be a bug. I hadn't quite understood what you were saying.

The patch itself doesn't look correct. You shouldn't need to declare forms in hook_forms() if they have the same name. I'm guessing this problem may be similar to #1332100: Prevent undefined function calls in component includes, where the .inc file just isn't loaded when you need it to be. The use of hook_forms() in your patch seems to be a work-around for the problem in a non-standard way (but probably does the job just as well). Instead of that approach though, we can use the new API function in D7 (which I just discovered this week) to ensure that the webform.components.inc file is pulled in during form processing: http://api.drupal.org/form_load_include.

quicksketch’s picture

Title: webform component "managed_file" element » Undefined function "webform_component_edit_form" called when using a managed_file element
Category: support » bug
Status: Needs work » Fixed
FileSize
1.2 KB

This patch should provide the same functionality and I think it's the correct approach for Drupal 7.

Status: Fixed » Closed (fixed)

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