Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I have tried to upload an image file by managed_file. Also I have set allowed extensions for managed_file form field.
Error message showing twice for invalid file format.
Steps to reproduce the problem
Create a Form with below code for form elements.
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['image'] = [
'#type' => 'managed_file',
'#title' => $this->t('Image ( allowed file formats: gif png jpg jpeg )'),
'#upload_location' => 'public://upload/image',
'#default_value' => '',
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Submit'),
];
return $form;
}
Upload a PDF file in order to see the bug.
Comment | File | Size | Author |
---|---|---|---|
form-error.png | 26.81 KB | syammohanmp | |
form.png | 13.1 KB | syammohanmp |
Comments
Comment #2
syammohanmp CreditAttribution: syammohanmp at Zyxware Technologies commentedComment #3
cilefen CreditAttribution: cilefen commentedThis doesn't come close to a critical issue. It looks to be a duplicate.
Comment #4
cilefen CreditAttribution: cilefen commented