Download & Extend

Undefined function "webform_component_edit_form" called when using a managed_file element

Project:Webform
Version:7.x-3.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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.

Comments

#1

Category:bug report» support request

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

#2

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.

AttachmentSize
webform_pic.module.txt 1.23 KB
file_managed_test.module.txt 614 bytes

#3

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.

#4

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.

#5

Status:closed (won't fix)» needs work

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

AttachmentSize
managed_file_upload-409154.patch 660 bytes

#6

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.

#7

Title:webform component "managed_file" element» Undefined function "webform_component_edit_form" called when using a managed_file element
Category:support request» bug report
Status:needs work» fixed

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

AttachmentSize
webform_client_form_includes.patch 1.2 KB

#8

Status:fixed» closed (fixed)

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

nobody click here