AnsweredAssumed Answered

Forms runtime sends Multipar data in background ???

Question asked by iblanco on Oct 7, 2010
I have configured a custom creation form for a custom type, and as I wanted to attach the content file as well as the metadata and the standard forms engine doesn't support file uploading yet I redirect the form to a API of mine, as well as sending it in multipart format instead of JSON.

I've duplicated the create-content page definition as well as the template instance and changed them slightly in order to specify the custom type as an argument of the page URL.

Now when I point to my custom page specifying my custom type as an argument and a destination noderef I get a form ready to submit to my custom API. It works, perfectly the file is uploaded with the correct type and metadata.

The problem is that there is  no redirection at all. At first I thought that if my API just gives back a JSON response in ther correct format (message and persistedObject attributes) javascript would do the magic, but it didn't. Later I've found this in components/form/form.js:

            
            // setup JSON/AJAX mode if appropriate
            if (this.options.enctype === "application/json")
            {
               this.formsRuntime.setAJAXSubmit(true,
               {
                  successCallback:
                  {
                     fn: this.onJsonPostSuccess,
                     scope: this
                  },
                  failureCallback:
                  {
                     fn: this.onJsonPostFailure,
                     scope: this
                  }
               });
               this.formsRuntime.setSubmitAsJSON(true);
            }

So it seems like when the submited content is in JSON format the submit is done in the background (AJAX) and that is where the JSON is handled back and interpreted. So I assume that when I send it in multipart format it should do the submit "in the foreground" and just show the resulting content parsed by the destination URL.

But it doesn't happen like this, it just submits it (I can see it through firebug) but without "changing the page", If my API gives JSON back the dialog for opening the file is thrown in Firefox (the browser, javascript, whatever doesn't now how to handle it), if my API gives back HTML it just ignores it. I can see through firebug that the response HTML has come back but there isn't any change in the page.

So it seems to me that even if it is a multipart submit it is done by an AJAX background process and the returned data just isn't parsed at all. Does it make sense ? Should I report this as a bug ?

Thanks

Outcomes