horst Posted January 8, 2018 Share Posted January 8, 2018 Hi, I have a use case where I want the user to select a local file, but the upload starts after he pressed save, and not directly via AJAX. Is it possible with our standard files field? Link to comment Share on other sites More sharing options...
kongondo Posted January 8, 2018 Share Posted January 8, 2018 Yes... $noAjax https://github.com/processwire/processwire/blob/57b297fd1d828961b20ef29782012f75957d6886/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module#L17 https://github.com/processwire/processwire/blob/57b297fd1d828961b20ef29782012f75957d6886/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module#L17 3 Link to comment Share on other sites More sharing options...
horst Posted January 8, 2018 Author Share Posted January 8, 2018 Thanks. I have a page with a filesfield, I hooked into ProcessPageEdit::buildFormContent and added the property noAjax = true. Result: the files drop area is gone, but when I select a file for uploading, it still gets uploaded directly. What I want is to select a file and its upload should start when I press the save button of the page. Is this possible? Link to comment Share on other sites More sharing options...
horst Posted January 8, 2018 Author Share Posted January 8, 2018 After some testing I now use a simple HTML file field embedded into a InputfieldMarkup: public function hookAfter_ProcessPageEdit_buildFormContent(HookEvent $event) { $p = $event->object->getPage(); if('my-desired-template-name' != $p->template->name) return; // early return !! $form = $event->return; $uploadField = "<input type='hidden' name='MAX_FILE_SIZE' value='{$this->MAX_FILE_SIZE}' />Diese Datei hochladen: <input name='userfile' type='file' />"; $f = $this->modules->get('InputfieldMarkup'); $f->attr('name', 'my_markup_fieldname'); $f->value = $uploadField; $form->add($f); // write back the modified form $event->return = $form; } In init or ready I check for the file fields value, and if a file is sent, I validate the file and add it to a hidden PW file field of the page. 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now