Saturday 10 June 2017

Processing request from basic form

I have problem with processing req that's coming from Post form.

Form looks like that

<form action="/" method="POST">

     <div class="form-group">
       <label for="city-input">City name</label>
      <div class="col-10">
       <input class="form-control" type="text" id="city-input" name="map-city">
      </div>
       <input type="checkbox" aria-label="..."/>
       <label style="color: #737373;font-family: 'Open Sans', sans-serif;line-height: 30px;">Choose or type</label>
      </div>

       <div class="form-group">
        <label for="example-text-input">Symbol</label>
        <div class="col-10">
        <input class="form-control" type="text" id="example-text-input" name="map-symbol">
        </div>
      </div>
      <button type="submit" class="btn btn-primary">Submit</button>          
</form>

I try to save each value into a virable

router.post('/', jsonParser, function(req, res, next){

 var test = req.body;
 var test0 = test.map-city;
 var test1 = test.map-symbol;

});

when I check what is is req.body i get

Object{map-city: "downtown", map-symbol: "dt"}

how to handle this to save each property to string

Now I get error - ReferenceError: city is not defined

Thank you



via cyprian

No comments:

Post a Comment