I am trying to create a field to upload the xml format of site map. But when I add a file to my filed it automatically uploaded and saved in the S3 bucket before I click on the submit button.
The issue is when someone added a xml file to that field and then closes the tab without submitting the form. The xml file is already uploaded to S3 bucket that way.
I need a way to manually upload this. I need to upload the image only after I pressed the submit button in the form. Without uploading the xml file automatically when selecting.
This is my buildForm() function.
public function buildForm(array $form, FormStateInterface $form_state) {
$form['sitemap'] = [
'#type' => 'managed_file',
'#name' => 'sitemap',
'#title' => t('Upload Site Map (xml)'),
'#upload_location' => 's3://private/sitemap',
'#field_suffix' => 'XML format supported',
'#upload_validators' => [
'file_validate_extensions' => ['xml'],
],
'#required' => TRUE,
'#validated' => TRUE,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Save configuration'),
'#attributes' => [],
'#validated' => TRUE,
];
return $form;
}
status
of0
and are mostly cleared on cron run.submitForm(array &$form, FormStateInterface $form_state)
. But the thing is it only executes after I clicked on the submit button. Is there a way to do it before auto upload happens?Drupal.behaviors.fileAutoUpload
. But I don't know to edit itjs-hide button js-form-submit form-submit
. Peace !