0

I'm pretty new to node and express, but i have set up an app with html files that i route between with app.sendFile(). I also have a working heroku postgreSQL database which i successfully can fetch from and write to.

I want the form below to send som query keywords which i send to a predefined query but with some variating parameters.

My question is how do I route and what methods I should use in app.js for this to work.

<form id="query-form" method="post" action="/dbquery">
    <label>Value1</label>
    <input class="form-control sendout-input" type="text" name="value1" placeholder="Filter sendout by Source"/>
    <br>
    <label>Value2</label>
    <input class="form-control sendout-input" type="text" name="value2" placeholder="Filter sendout by Country"/>
    <br>
    <label>Value3</label>
    <input class="form-control sendout-input" type="text" name="value3" placeholder="Filter sendout by Lanuage"/>
    <br>
    <button class="btn btn-default" type="submit">Submit</button>
</form>

How do i get the value of these input fields in my app.js? My guess is something similar to this:

app.post('/dbquery', function(request, response) {
     var first = request.myInputvalues.value1
     var second = request.myInputvalues.value2
     var third = request.myInputvalues.value3

     // Send query with these variables to the 
});
Community
  • 1
  • 1
A. Larsson
  • 1,319
  • 11
  • 16

1 Answers1

0

If you post to that route you should be able to access the body of the request you sent in request.body inside of the handler.

See this related question: How do you extract POST data in Node.js?

Nathan Lynch
  • 455
  • 3
  • 11