Interesting POST fetch issue

Hello all, My company works with real estate agents across the U.S… I’ve been working on a feature that would allow me to add a new agent to our database using an asynchronous POST fetch. The function looks like this, in part.

    fetch(source, { 
        body: new FormData(newAgentForm),
        headers:{ "Content-Type":"multipart/form-data" }
    } )
    .then( (data)=>{

“source” is a variable that contains a string to the cfc i’m sending the data to and newAgentForm contains the form information I’m sending. Through my console window I see that I’m sending the following:

On the Lucee side of things I’ve a cfc that has a function that looks like this:

remote any function createNewAgent(){}

I’ve tried to catch the incoming data within the form scope but it’s not seeing it. In some of my first attemtps I just tried echoing back one of the form field values as in

return form.newagent_fname;

I tried to return the built-in fieldnames variable (return form.fieldnames) but both former and the latter test returned something similar to this

To see if I was getting anything in the function I added the attribute returnformat=‘plain’ to the function. Then within the function I did this:

var data = getHTTPRequestData();
return data.content;

and I got this back

It looks like function is getting the data but it’s just not being put into the form scope. I’ve even tested the cgi.REQUEST_METHOD to make sure it was being sent via post and it was positive.

Does anyone have any ideas on how to make the two ends connect?

1 Like

I’ve not tested it or used it any time recently, but I believe it will place it into the argument scope of the function, so maybe try:

remote any function createNewAgent(inputData) {
    return arguments.inputData;

and see what you get.

I would, however, recommend using something like the REST functionality of ColdBox or similar instead.

@andrew Thanks for the response. I tried out your suggestion, but no luck. The function isn’t receiving any arguments. I’m thinking I might just go with a standard form submission. Not as fun, but it’ll get the job done.