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.
Comment | File | Size | Author |
---|---|---|---|
#7 | webform_client_form_includes.patch | 1.2 KB | quicksketch |
#5 | managed_file_upload-409154.patch | 660 bytes | nevergone |
#2 | webform_pic.module.txt | 1.23 KB | nevergone |
#2 | file_managed_test.module.txt | 614 bytes | nevergone |
Comments
Comment #1
quicksketchIs this a question about how to write a custom component? I don't help with custom coding in the issue queue.
Comment #2
nevergone CreditAttribution: nevergone commentedThe 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.
Comment #3
quicksketchAs mentioned in the submission guidelines, I don't provide help with custom coding:
Please refer to other resources such as IRC or Drupal StackExchange to ask your questions.
Comment #4
nevergone CreditAttribution: nevergone commentedOkay, 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.
Comment #5
nevergone CreditAttribution: nevergone commentedPatch is included latest Webform 7.x-3.x, test module is here: http://drupal.org/node/1409154#comment-5485196
Comment #6
quicksketchThanks, 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.
Comment #7
quicksketchThis patch should provide the same functionality and I think it's the correct approach for Drupal 7.