I have made a form using 3rd party plugins (multiple and wmd-editor). My HTML is :
<form id="form" class="form" method="post" action="/questions">
<div id="title" class="form__title">
<div id="question_title">Title</div>
<input id="input_element1" class="input_element" type="text" placeholder="What's your programming question? Be specific." name="title">
</div>
<div class="text-area">
<div id="wmd-button-bar"></div>
<br/>
<textarea id="wmd-input" name="text"></textarea>
<div id="wmd-preview"></div>
<br/>
</div>
<div class="inputtags form__tags">
<select id="options" multiple="multiple" name="tags">
</select>
<div class="inputtags__element"></div>
<div class="inputtags__errors"></div>
<br>
<div id="inputtags__post">
<button class="btn" id="btn-submit">
Post Your Question
</button>
<button class="btn" id="btn-discard">
Discard
</button>
</div>
</div>
</form>
I am putting tags in the options select using the javascript and the javaScript code is:
var index = -1;
var htmlStr = tags.reduce(function(a,b){
index++;
return a + "<option value="+(index+1)+" name="+b+">"+b+"</option>";
},'');
$("#options").html(htmlStr);
I am fetching these in the routes file of my node.js (express framework) as :
router.post('/questions', function(req,res){
var question = req.body;
console.log(question);
Question.createQuestion(question);
res.redirect('/');
});
Here req.body should give me the name of DOMs as suggested in expressjs Documentation. I have given name to my option in my javascript code but still when the data is pushed to the database, the req.body return me following:
{
title: 'title',
text: '<p>Body</p>',
tags: [ '1', '2', '3', '4', '5', '6', '7', '8' ]
}
My code in app.js:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var mongoose = require('mongoose');
var passport = require('passport');
var flash = require('connect-flash');
What I am doing wrong?