parsing jade forms with node.js

1k Views Asked by At

I'm not sure how to go about getting a user selected item from a dropdown list. My jade code is pretty short:

extends layout

block content
  p This is the CSV page
  p <select>
    <option value="domain">Domain</option>
    <option value="test">Test</option>
    <option value="random">Random</option>
    <option value="databases">Databases</option>
  </select>
  form(action="/csvuploader", method="post", enctype="multipart/form-data")
    label(for="payload") Select a file to upload:
    input#payload(type="file" name="myFile" accept="/*")
    br
    button#upload Upload

using some busboy methods in my /csvuploader file referenced in the 'action' part of the file upload form I have successfully saved the file. How can I now access the value selected from the dropdown list just before it?

Apologies if this sounds like a really stupid question, I'm new to node.js and forms. Thanks.

1

There are 1 best solutions below

4
On BEST ANSWER

You need to move the <select> to inside the <form> element, and also give it a name:

form(action="/csvuploader", method="post", enctype="multipart/form-data")
  p This is the CSV page
  p
    select(name = "dropdown")
      option(value="domain") Domain
      option(value="test") Test
      option(value="random") Random
      option(value="databases") Databases
  label(for="payload") Select a file to upload:
  input#payload(type="file" name="myFile" accept="/*")
  br
  button#upload Upload

After that, you can read the value of the dropdown from req.body.dropdown.