Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
file.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Feb 2012 at 16:14 UTC
Updated:
14 Feb 2022 at 07:58 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
arne_hortell commentedHi,
I changed this (514)
$elements['#file_upload_description'] = theme('file_upload_help',array( 'description' => '','upload_validators' => $elements[0]['#upload_validators']));
To this
// To prevent error when form_submitted programatically
if (array_key_exists(0,$elements))
$elements['#file_upload_description'] = theme('file_upload_help',
array( 'description' => '',
'upload_validators' => $elements[0]['#upload_validators']));
Comment #2
yched commentedRecategorizing
Comment #3
altcom_alan commentedThis problem also cascades into image_field_widget_form() in image.field.inc line 358 which basically has the same line of code:
$elements['#file_upload_description'] = theme('file_upload_help', array('upload_validators' => $elements[0]['#upload_validators']));This generates the same warning when submitting a form programatically, so it seems to me the fix should be to remove the check for a programmed form from the code that adds the empty row in line 488 which will mean there will allways be a $elements[0]:
if (($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta < $field['cardinality']) && empty($form_state['programmed'])) {becomes:
if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta < $field['cardinality']) {I've not yet tested but I don't see why the widget would do anything strange when it's a programmed form if there is an empty row.
Comment #4
musicalvegan0 commentedI can confirm that this is still an issue with Drupal 7.23:
I can also confirm that #1434312-1: file_widget_multiple doesn't allow programmatic form submission solves the issue.
Submitting patches against current 7.x.
Comment #5
mccrodp commentedOn Drupal 7.27 this patch did remove the PHP Notice, but it did not assign the files to the indexes correctly. When the image field's "Number of values" is set to 1 the 1st field below as part of the JSON node to be imported works correctly and the existing image on the server is assigned to the field in Drupal. When the image field's "Number of values" is set to greater than 1, neither image is associated.
No errors or anything suspicious found in the logs: admin/reports/dblog
Any ideas? Are we sure this works in Drupal 7.27?
EDIT: Sorry, this is most likely due to a related issue with Services module.
Comment #6
tkuldeep17 commentedComment #7
digitalfrontiersmediaIs this the same problem as #1912458: file_field_widget_form() broken when submitting programmatically a form having a multiple file field?
Comment #8
kaareDoes anyone have a cool workaround for this without hacking/patching core? Otherwise, after a quick inspection of the code in question, I think the solution in #3 is on the right path. Either remove the test for whether the form is programmed, or add an additional test for whether it is programmed during the manipulating of
$elements['#file_upload_description'].Comment #9
isinadinos commentedI patched core with #4 but it didn't work. Is this code applicable for services 3.14 version?
I upload the image first and i got response fid. Then I post the following json but I can't see the image in the node.
{
"title": "Report Problem",
"type": "report",
"language": "und",
"uid":"1",
"body" : {
"und": [
{
"value": "test body"
} ]
},
"field_tags": { "und": "2" },
"field_image": {"und": [{"fid":"13"}]}
}
Any suggestions?