-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Module version(s) affected
4.x, 5.x
Description
Using FileField in the cms is not possible because files are not submitted due to how the form is submitted through ajax.
This is an issue because it means it's not always practical to "send files" not meant to be saved as assets, but for example as import templates or whatever.
Issue for reference:
lekoala/silverstripe-pure-modal#8
How to reproduce
Have a model admin instance and a model
Have this
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Upload', new FileField("TestFile"));
...
public function onBeforeWrite()
{
parent::onBeforeWrite();
dd($_FILES)Select a file, click save and close, and see how $_FILES is empty
Possible Solution
i believe it's due to how the form is submitted by LeftAndMain see here
silverstripe-admin/client/src/legacy/LeftAndMain.js
Lines 539 to 546 in 0517656
| // get all data from the form | |
| var formData = form.serializeArray(); | |
| // add button action | |
| formData.push({name: $(button).attr('name'), value:'1'}); | |
| // Artificial HTTP referer, IE doesn't submit them via ajax. | |
| // Also rewrites anchors to their page counterparts, which is important | |
| // as automatic browser ajax response redirects seem to discard the hash/fragment. | |
| formData.push({ name: 'BackURL', value: document.URL.replace(/\/$/, '') }); |
it should really be replaced by a simple FormData that should work fine instead
https://stackoverflow.com/questions/41684385/how-to-add-file-value-with-jquery-serialize
This should be really easy to fix, I'm happy to give it a try
Additional Context
No response
Validations
- Check that there isn't already an issue that reports the same bug
- Double check that your reproduction steps work in a fresh installation of
silverstripe/installer(with any code examples you've provided)