If we process form programmly (use $form_state['programmed'] flag) there are no reasons to add triggering element to form_state:
function _form_builder_handle_input_element (form.inc)
if ($process_input) {
// Detect if the element triggered the submission via Ajax.
if (_form_element_triggered_scripted_submission($element, $form_state)) {
$form_state['triggering_element'] = $element;
}
// If the form was submitted by the browser rather than via Ajax, then it
// can only have been triggered by a button, and we need to determine which
// button within the constraints of how browsers provide this information.
if (isset($element['#button_type'])) {
// All buttons in the form need to be tracked for
// form_state_values_clean() and for the form_builder() code that handles
// a form submission containing no button information in $_POST.
$form_state['buttons'][] = $element;
if (_form_button_was_clicked($element, $form_state)) {
$form_state['triggering_element'] = $element;
}
}
}So when we validate form after programmly processing we have dsm warrning:
Warning : end() expects parameter 1 to be array, null given dans file_managed_file_validate() (ligne 550 dans /home/i20/prj/culturebox/public/modules/file/file.module).
There are string that cause this :
/**
* An #element_validate callback for the managed_file element.
*/
function file_managed_file_validate(&$element, &$form_state) {
// If referencing an existing file, only allow if there are existing
// references. This prevents unmanaged files from being deleted if this
// item were to be deleted.
$clicked_button = end($form_state['triggering_element']['#parents']);| Comment | File | Size | Author |
|---|---|---|---|
| #1 | avoid_php_notice_when_form_processing_programm-1886750-0.patch | 841 bytes | pavel ruban |
Comments
Comment #1
pavel ruban commentedThere are some resolve issue solution needs review
Comment #2
btopro commentedJust ran in circles tracking this down myself. This is still an issue with 7.27. To confirm OP; this happens when you submit a form using drupal_form_submit() and the form you are submitting has a managed file field in it. In my use case the file is optional and I wasn't submitting a file, causing the error since it is checking to see what button was pressed (which a CLI / function processing the form won't have processed).
Proposed patch passes automated testing and review looks reasonable. Without this patch all drupal_form_submit calls will need to have the following added to avoid the error: