I just tried to create a simple mandatory file upload field in a custom form like this:
public function buildForm(array $form, FormStateInterface $form_state) { $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['pdf_file'] = array( '#type' => 'file', '#title' => $this->t('PDF File'), '#description' => $this->t('PDF files only'), //'#multiple' => TRUE, '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => $this->t('Save'), ); return $form; }
And that did not work.
When submitting a file (no matter what kind of), i get this error all the time:
“PDF File field is required.”
Does anybody have an idea what I am doing wrong?
I am using Drupal 8.2