In my CFM file, I have a form that I need to send it as JSON. This is my first time trying to send a form as JSON data. I have looked at the example in W3C HTML JSON form submission but I do not see an example on how to specify the json URL. I saw that the form's enctype attribute has to be set to application/json but that's pretty much it. I need to know where I specify the jsonp URL, authkey, and other parameters that are required to submit to the proper location. Since I'm using ColdFusion, I'm not sure if I should continue using ColdFusion tags for JSON submission or Javascript and/or JQuery. Any suggestion is much appreciated. By the way, the authkey needs to be private since this is a post. Below is my form I've gotten so far.
The remote API service accepts the data as follows. So, I need some way in the form to specify these criteria.
stdClass Object
(
[valid] => 1
[data] => stdClass Object
(
[id] => 54f126ed7cb82991627b23f0
[type] => comment
[project_id] => 54b88f0ffe775aac57000001
[article_id] => 54b88f12bfe5a1601400001c
[author_id] => 52d9a8dbfe775ad80d000001
[content] => I'm a comment!
[public_name] =>
[public_email] =>
[user_submitted] => 1
[date_created] => 02/27/2015 9:24 pm EST
)
)
Okay, looks like I have to build the JSON string before I do a form submission to itself and do a CFHTTP tag to send the JSON data. Below is what I have so far:
<cfset jsonString ={
data = {
article_id = "#artID#",
type = "comment",
project_id = "55c4ffd123131c527e294fe6",
content = "#form.message#",
public_name = "#form.name#",
public_email = "#form.mailfrom#"
}
}>
<cfhttp url="https://app.kb.com/api/head/comment.json" method="post" timeout="15" throwonerror="true" >
<cfhttpparam type="body" name="body"value="#serializeJSON(jsonString)#" />
</cfhttp>
However, it's not working. I'm still not totally clear on what the CFHTTPPARAM should be since now I am manually building all the parameters as a string instead of submitting them individually inside the CFHTTP tag. Any help is much appreciated.