# Capture user data and Post to server as response

**URL:** <https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245>\
**Category:** General\
**Created:** [18 September 2018 17:33 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245 "2018-09-18T17:33:29Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![quique123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quique123/32/2630_2.png) [@quique123](https://discourse.nodered.org/u/quique123)\
**Post date:** [20 September 2018 18:21 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/21 "2018-09-20T18:21:20Z")

</div>

The thanks template node? Displays the thank you for the client.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 September 2018 18:35 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/22 "2018-09-20T18:35:43Z")

</div>

So as the msg travels from left to right  
msg.payload starts being an object with the 2 vars  
you then pass it through a template and change msg.payload to be your Thanks message  
But your next node (the function node) then can't do a calculation on the to vars as you have just replaced them with the function node.

---

<div class="post-metadata">

**Author:** ![quique123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quique123/32/2630_2.png) [@quique123](https://discourse.nodered.org/u/quique123)\
**Post date:** [20 September 2018 19:19 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/23 "2018-09-20T19:19:39Z")

</div>

OK but then I don't understand because I used msg.payload.results so that the other data won't get destroyed. Where am I destroying the vars?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2018 19:47 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/24 "2018-09-20T19:47:44Z")

</div>

What does the 'thanks' template node do?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 September 2018 20:32 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/25 "2018-09-20T20:32:57Z")

</div>

You are destroying the vars with the template node "thanks" that according to your screenshot puts the message in msg.payload as a string

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [20 September 2018 20:34 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/26 "2018-09-20T20:34:06Z")

</div>

I guess your "thank you" node is setting `msg.payload` to be some html string, which is replacing the `msg.payload` **object** (and all of its `var1`, `var2`, and `results` properties).

Are you wanting to return the calculated difference in the rendered "thanks" page? That would make sense, so if you received bad data, you could change the output page to show the problem.

Either way, you cannot have 2 outputs wired into 1 `http response` node. In the meantime, it might help if you understand more about javascript datatypes and object/array structures. I like the [W3Schools introduction to JS datatypes](https://www.w3schools.com/js/js_datatypes.asp), and their references dealing with [JS Objects](https://www.w3schools.com/js/js_objects.asp) and [JS Arrays](https://www.w3schools.com/js/js_arrays.asp). There are also some good examples of how to work with [Node-RED msg objects](https://nodered.org/docs/user-guide/messages) specifically, in case you have not seen it.

---

<div class="post-metadata">

**Author:** ![quique123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quique123/32/2630_2.png) [@quique123](https://discourse.nodered.org/u/quique123)\
**Post date:** [20 September 2018 20:50 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/27 "2018-09-20T20:50:45Z")

</div>

Yes I'm trying to display the result in the thanks page. OMG, ok i dont know how I got so confused. So I moved the function node after the post node and connected the function node to the http response and it works now. So now how do I display the result in the thanks page?

At present the debug node shows the result and the http-response is giving a plain text html json as a result. I do understand objects, I just dont understand how the flow works in node-red, or not the flow but rather how to access things. So if the result is being passed in the message object to the http-response node, this is done automatically by node red and so simply setting the node's headers to content-type plain text, it will display the object in json format. The http-response node gets it because the function node passes it in its code "return msg;".

But how do I also send it to the thanks template html page, where I can work with html code and make the results prettier for the user?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2018 21:39 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/29 "2018-09-20T21:39:42Z")

</div>

I suggest you go read the 'info' tab of the template node....

---

<div class="post-metadata">

**Author:** ![quique123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quique123/32/2630_2.png) [@quique123](https://discourse.nodered.org/u/quique123)\
**Post date:** [20 September 2018 21:41 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/30 "2018-09-20T21:41:43Z")

</div>

ok great! I like your style:

1. So the post node sends the values in the msg object to the function node.

2. The function node stores them in msg.payload.var1 and var 2 and also processes the result and stores it in the msg.payload.result, so it passes {"var1":"33", "var2":"44", "result":"77"} the object to the objects downstream from it.

3. thanks template is one of those nodes and http-response is the other node that will get the msg object. The http-response node is getting it just fine, as a header content type and displaying it as text. But the thanks node is not getting it.

So I think I need to somehow capture that msg object in the thanks template html code. This is what I dont know how to do, Im not very well versed in html. Unless there is a different way I should be doing it?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2018 21:44 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/31 "2018-09-20T21:44:10Z")

</div>

Note, I edited my last post because you had found some of the answer, so now go read the info tab of the template node, you are almost there.

---

<div class="post-metadata">

**Author:** ![quique123](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/quique123/32/2630_2.png) [@quique123](https://discourse.nodered.org/u/quique123)\
**Post date:** [20 September 2018 21:57 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/32 "2018-09-20T21:57:43Z")

</div>

GOT IT!!!

```
<html>  
  <head>
  </head>
  <body>
      {{payload.result}}
    <h1>Thanks for signing up!</h1>
    <p>You're all set.</p>
  </body>
</html>  

```

When I enter 22 and 33 and submit, I get 55 in the template debug node.

So the only problem I have now is that the json string displayed after clicking submit is the msg object presented by the http-response node. How do I make the thanks template to be the displayed node instead, so I can see my nice html result?

Looking around I found this which is nice: [https://medium.com/node-red/node-red-design-patterns-893331422f42](https://medium.com/node-red/node-red-design-patterns-893331422f42)

Got it!

 ![58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/355547fac00aceb4eb500b2df10df2dbb8c345d4.png)

 ![21](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/02b6547a86a4f2ae77dc679079a93d907a24ceed.png)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2018 22:11 UTC](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245/33 "2018-09-20T22:11:15Z")

</div>

Good Job, you get an A+

[Previous page](https://discourse.nodered.org/t/capture-user-data-and-post-to-server-as-response/3245.md?page=1)
