I'm getting the error Notice: Undefined index: #value in element_validate_integer_positive() (line 4190 of includes\form.inc)
after clicking the Upload
or Remove
of a managed_file
even though the file is actually being stored in the correct directory.
Here's the relevant snippet:
$form['some_image'] = array(
'#title' => t('Image'),
'#type' => 'managed_file',
'#description' => t('The uploaded image will be displayed on this page using the image style choosen below.'),
'#default_value' => variable_get('some_image', ''),
'#upload_location' => 'public://some_images/',
);
I'm running the instance on XAMPP with PHP 5.3.6. Downgrading to PHP 5.2.9 didn't fix the problem as indicated in the other forums.
When I use Chrome to checkout the ajax request URL, I see the message that is also seen from looking at file/ajax/image/file/form-wRaEJ-JRPqC7q6BSbp6Ccxi_9X1cpiaBzhwlIs9NFd0
that I found from /admin/reports/dblog
Error message An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (512 MB) that this server supports.
Note that I'm only uploading a 100kb file.
Line 4190 of includes/form.inc
is as follows:
function element_validate_integer_positive($element, &$form_state) {
$value = $element['#value'];
if ($value !== '' && (!is_numeric($value) || intval($value) != $value || $value <= 0)) {
form_error($element, t('%name must be a positive integer.', array('%name' => $element['#title'])));
}
}
Update: It turns out the problem is not just for the managed_file
, but also for the form itself. Clicking the submit button shows the very same error.
Currently, my hook_form_validate
is as follows:
function mymodule_form_validate($form, &$form_state) {
}
Removing it gives me a Drupal error that says it should be there. I think I'm missing an implementation some other hook, but I have no idea which.
What am I missing here?
It turns out the problem was coming from an entirely different field from the same form whose #type
incorrectly valued with numericfield
. I had to remove all my form fields and search which of them was causing the error.
It looks like the managed_file
fields also trigger the validation for all the other fields in the same form when the Upload
button is clicked.