Jump to content

[SOLVED, partly] is inputfield files usable without the ajax functionality?


horst
 Share

Recommended Posts

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
  • Like 3
Link to comment
Share on other sites

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

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.

:)

  • Like 4
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...