html - post form data and show in server -


i have simple form, want see fields sent server. in server side, <input type="text"> field value. why server can't <select> , <input type="file" /> value?

html:

<form action="http://localhost:8100/" method="post">         <div>             <select>                 <option value="op1" selected="selected">option1</option>                 <option value="op2">option2</option>             </select>         </div>          <div>             <input type="file" value="select file"/>         </div>          <div>             <label>your hero: </label><input type="text" name="hero" />         </div>          <input type="submit" value="submit" />     </form> 

server:

var http = require("http");  http.createserver(function(req, res) {         if (req.method == 'post') {             var body = '';             req.on('data', function (data) {                 body += data;                 console.log(body);             });             req.on('end', function () {                 console.log("request data complete");             });             res.end("post request");         } else {             res.end("get request");         }      }).listen(8100); 

your select , file input elements missing name attribute. form elements wish submitted must have unique name attribute. name attribute identifier value of element when data has been submitted through post , get.

you can read in specs in here: http://www.w3.org/tr/html5/forms.html#naming-form-controls:-the-name-attribute


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -