Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Mar 2011 at 10:36 UTC
Updated:
20 Mar 2013 at 07:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jesse.rosato commentedSeconded.
Comment #3
pivanov commentedThe extra added buttons (upload and remove) seem to be causing this. They don't seem to have any values and one thing the submit handler (added by system_settings_form()) does is to remove any values buttons may have added to from $form_state['values'].
One possible way is to set the '#parents' attribute of each upload and remove button to an empty array. However, I don't know if this is a good idea.
In a submit handler (ran before the system_settings_form() one):
Comment #4
dealancer commentedLooks like managed_file don't work well with system_settings_form and should be processed manually. To fix this problem, see solution below
Here is my form:
and here is a custom submit:
That's all.
However, we should except by processing this field by submit added in system_settings_form().
Comment #5
dealancer commentedLooks like managed_file doesn't work well with system_settings_form and should be processed manually. To fix this problem, see solution below
Here is my form:
and here is a custom submit:
That's all.
However, we should except by processing this field by submit added in system_settings_form().
Comment #6
jaimealsilva commentedI have tried this on a theme's theme-settings.php:bla_form_system_theme_settings_alter() by adding "bla_settings_form_submit" to #submit but I get the error:
PHP Fatal error: Call to undefined function bla_settings_form_submit() in /.../includes/form.incHow can I specify on which file to find the function ? Or where should I put the function ?
Thanks.
Comment #7
aviddv1 commentedHave you tried using:
$form['#submit'][] = 'my_custom_form_submit';inside your custom form function? That should tell Drupal to submit the form data to your _submit function.
I found I had to modify the example to get it to work.
- added a condition to check if the custom_file_1 value > 0
- if the condition fails then I attempt to load the file object from the saved variable, check if the object exists, manually force delete the file
Comment #8
BarisW commentedUsing a custom variable and unsetting the form_value works for me. Another way to get this working is by adding an is_array() check in forms.inc on line 2144:
Change:
To:
Comment #9
BarisW commentedBy the way, this still applies in Drupal 7.x-dev
Comment #10
thursday_bw commented+1 for BarisW's solution with the core patch.
I had the task of converting the user_profile form into an inline ajax save.
This was one of many challenges that needed solving in that case, when
converting the picture_uploaded field to ['#type'] => 'managed_field';
BarisW's solution would solve it conveniently.
My solution was to prepend a submit handler, and to unset all the buttons that had a submit handler
called 'file_managed_file_submit', (this avoided a core patch, and does the job for the custom module).
It is not ideal however as the default submit handler could be overridden for a such a field.
Comment #11
lsolesen commentedRolled patch for the solution proposed by BarisW.
Comment #12
sunMarking as duplicate of #635046: form_state_values_clean() is polluting form values (followup), which has a solution that was already accepted for D8, so just needs proper backporting/testing.
Comment #13
andriy commentedthis worked perfectly for me, by unsetting upload and remove buttons added by managed_file
Comment #14
andrezstar commented<?php
#13 thanks for the explanation, you made my day.
Just a little addition:
On the deletion, shouldnt we check that the $file->fid exists? I mean, otherwise, when you have no file uploaded, it would be trying to delete it.
Comment #15
rahulkumar.it commentedthanks andriy for the explanation,You save my time.