POST Custom Form Values to another server


(Nic Hubbard) #1

I have used Matrix for years, but only now am needing to do this.

 

Is it possible to have a user fill out a Custom Form, on and Submit, those values can get POSTed to another URL? I know there is the Make SOAP Call, which is similar, but not what I need.

 

Ideas?

 

(If this isn't possible I will just write a new Submission Action)


(Bart Banda) #2

Can you use the http://manuals.matrix.squizsuite.net/custom-form/chapters/form-contents#call-rest-resource submission action for this and just pass all the values through that? 

 

There is also a brand new keyword and modifier that has been added in the latest release (not documented in manuals yet though as it just came out) that allows you to print all POST data with 1 keyword and use modifiers to print it in different formats, XML, JSON or CSV: http://bugs.matrix.squiz.net/view_bug.php?bug_id=6517

 

Could you use that?


(Nic Hubbard) #3

Could you use that?

 

Actually I think this is exactly what I need! Will give it a try.


(Mahearnpad) #4

Hi Nic

 

I'm trying to do a similar thing, but I want to POST to a RESTful webservice on another server/domain, via JavaScript.  Have you done this before in Matrix?  Is it in fact possible?  I'd thought that I could use the REST JS Resource asset as a "proxy", and use that to do the POST to the webservice.  I can't work out how to do this exactly though (that is, I can't work out how to pass the form data to the REST resource, and then have that pass it on to the webservice api.

 

Other thing is, I think we have a version of Matrix that is missing a lot of patches and enhancements around this sort of thing (v. 4.12) ;(

 

Any ideas would be useful. TIA

Michael


(Nic Hubbard) #5

I'm trying to do a similar thing, but I want to POST to a RESTful webservice on another server/domain, via JavaScript.  Have you done this before in Matrix?  Is it in fact possible?  I'd thought that I could use the REST JS Resource asset as a "proxy", and use that to do the POST to the webservice.  I can't work out how to do this exactly though (that is, I can't work out how to pass the form data to the REST resource, and then have that pass it on to the webservice api.

 

Hi Michael,

 

Unfortunately I have not had any experience with doing this. Why do you have to use javascript for this?


(Mahearnpad) #6

We have to use JS because it will be done from one of the Matrix custom forms - actually from the e-commerce assets - but we need to store the orders on another server.


(Nic Hubbard) #7

We have to use JS because it will be done from one of the Matrix custom forms - actually from the e-commerce assets - but we need to store the orders on another server.

 

What about using the Run Database Query Submission Action?


(Mahearnpad) #8

I haven't looked at this, but we need to send the form data to a WCF API, and any db queries will be securely abstracted away in stored procedures, for security reasons. So this doesn't sound like an option.


(Anthony) #9

Michael - I did a proof of concept a month or two ago using the technique you describe. In JS I POST to a local URL within my Squiz instance which is a REST resource asset. That then makes a call to a third party system. I was trying to get data into a PDF file using the "webmerge.me" service. I hardcoded a few things for my proof of concept, but I got far enough to know it would meet my needs. I havent yet had time to go back and implement the full solution, its still working its way up the priority list!!


(Mahearnpad) #10

That's good to hear Anthony. So was it a POST call you made from the proxy? The answer i need to find out is HOW to get pass through the values from the client form, to the proxy, then on to the final web service - which accepts a POST request.

 

If you could elaborate on this part, I would be most thankful :)


(Bart Banda) #11

Hi Nic

 

I'm trying to do a similar thing, but I want to POST to a RESTful webservice on another server/domain, via JavaScript.  Have you done this before in Matrix?  Is it in fact possible?  I'd thought that I could use the REST JS Resource asset as a "proxy", and use that to do the POST to the webservice.  I can't work out how to do this exactly though (that is, I can't work out how to pass the form data to the REST resource, and then have that pass it on to the webservice api.

 

Other thing is, I think we have a version of Matrix that is missing a lot of patches and enhancements around this sort of thing (v. 4.12) ;(

 

Any ideas would be useful. TIA

Michael

 

Sounds like you should still be able to use the http://manuals.matrix.squizsuite.net/custom-form/chapters/form-contents#call-rest-resource on the custom form form submission action. You should be able to reference any POST data using the standard response type keywords that you would use on the thank you page or the email options screen. Have you given this a try?


(Anthony) #12

Michael,

 

In my main page, i use jQuery to POST to my rest resource asset. jQuery does the hard work of turning a simple object into the necessary POST parameters. In reality my data is generated dynamically, but heres a very simple hardcoded example: (22761 is the asset ID of my rest resource asset)

 

var oData; oData = {
school: "Test schools name",
chair: "Chairman name",
speaker: "Speakers name",
topic: "This is the speakers own topic"
};
$.post("./?a=22761", oData);
 

 

In the REST resource asset, I set the Method to POST, fill in the URL I want to post to (in my case webmerge.me/....) and any authentication. Then in the Request Body field, I simply set out all the keyword/value pairs I want to POST on to that service, and for the values I use the keywords representing the values posted to this asset, which in turn were the names of the properties of my original javascript object. To keep life simple, I use the same variable names for each bit of data. So here's my example request body:

 

School=%globals_post_school%&Chair=%globals_post_chair%&Speaker=%globals_post_speaker%&Topic=%globals_post_topic%

 

Hope that helps!!

Anthony


(Mahearnpad) #13

Exactly what I needed! Thanks for taking the time to write this comprehensive reply Anthony.