FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

How to use with req.body? · Issue #42 · tj/node-querystring · GitHub

How to use with req.body? #42

Description

Hi - trying to figure out how to parse square bracket notation in a form (user[1][name]...) but can't seem to get this going in Express3. I just get junk. Tried passing req.body to qs.parse but that did nothing and I am not finding docs on this.

To give an idea of what I get....

My form looks a bit like this (non necessary html removed):

<input name="title" value="My title"/>
<input name="variant[0][name]" value="color"/>
<input name="variant[0][entries][0][label]" value="red"/>
<input name="variant[0][entries][0][price]" value="2"/>
<input name="variant[0][entries][1][label]" value="blue"/>
<input name="variant[0][entries][1][price]" value="3"/>

Then I do:

var qs = require('qs');
var body = qs.parse(req.body);
console.log(body);

Console output:

{ 
title: 'My title',
variant: 
 [ ,
   ,
   ,
   ,
   ,
  (there are approx 850 of these commas)
   ,
   ,
   { name: 'color', entries: [Object] } ] 
}

If I console.log(req.body):

title: 'My title',
'variant[0][name]': 'color',
'variant[0][entries][0][label]': 'red',
'variant[0][entries][0][price]': '2',
'variant[0][entries][1][label]': 'blue',
'variant[0][entries][1][price]': '2'
}

Thanks for your time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL