Problem responding to html select option

am trying post the value of html select option,
but each time i post the page will display blank. am using normal req.body to respond. it seems the strategy is different. please help

profile.pug:

DOCTYPE
html(lang="en")
  head
    title profile page
    meta(name='description', content='Preparing Personal Portfolio')
    meta(charset='utf-8')
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width, initial-scale=1')
  body
    div.profile-page
      h1.center#Welcome welcome, #{username}!
      p This is your profile page where your personal data, and transaction can be made
    div.file-form
      form(action="/file" method="post")
        div.label
          label choose file
          input(type="file", name="file")
          br
          input(type="submit", value="submit")
    hr      
    div.message-form
      form(action="/messages" method="post")
        div.dropdown-button
          label(for="manager") Choose Pass-Request Manager   
          br
          select(name="manager") 
            option(disabled, selected) Choose Manager
            option(value="firstManager") firstManager
            option(value="secondManager") secondManager
          br
        div.text-area
          label(for="message") Compose Text in the Text-Area 
          br
          textarea(type="text" name="message" id="message" placeholder="Text here")
          br
          input(type="submit", value="submit")
              
           
              
              
      a(href="/logout") logout
    

user.js

const express = require("express");
const path = require("path");
const {handleReg,  handleLogin, handleMessage, handleLogout} = require("../controller/auth");
const {loginEng} = require("../passport/index");
const passport = require("passport");
//const local = require("../passport/local");
const {registerValidator,
       loginValidator,
       validationErrorsHandler} = require("../middleware/validator");

module.exports = function(app){
  
  app.route("/").get(function(req, res){
    res.render(__dirname + "/../views/index.pug");
  });
  
  app.route("/register").get( function(req, res){
    res.render(__dirname + "/../views/regForm.pug");
  });
  
  //ensure login helper function
  function ensureAuthentication(req, res){
    let isAuth = req.isAuthenticated();
    if(!isAuth) throw " Error authenticating login";
  };
  
  app.route("/login").get( function(req, res){
    res.render(__dirname + "/../views/login.pug");
  });
  
  app.route("/profile").get(ensureAuthentication, function(req, res){
    res.render(__dirname + "/../views/profile.pug");
  })
  
  app.route("/register").post([...registerValidator,  validationErrorsHandler], handleReg);
   
  app.route("/login").post( passport.authenticate('local', { session: false }),  handleLogin);
  
  app.route("/messages").post(function(req, res){
  const managers = {
  'firstManager': 'firstManager',
  'secondManager':'secondManager',
   // etc
}
  console.log(req.body.managers);
  res.send(req.body.managers); 
});
  
  app.route('/logout').get(handleLogout);
  
  
}    

project link Glitch

Hi,

Can you please brief your question a little more?. I am not able to see any select option from your project link.

1 Like

The files
profile.pug:

DOCTYPE
html(lang="en")
  head
    title profile page
    meta(name='description', content='Preparing Personal Portfolio')
    meta(charset='utf-8')
    meta(http-equiv='X-UA-Compatible', content='IE=edge')
    meta(name='viewport', content='width=device-width, initial-scale=1')
  body
    div.profile-page
      h1.center#Welcome welcome, #{username}!
      p This is your profile page where your personal data, and transaction can be made
    div.file-form
      form(action="/file" method="post")
        div.label
          label choose file
          input(type="file", name="file")
          br
          input(type="submit", value="submit")
    hr      
    div.message-form
      form(action="/messages" method="post")
        div.dropdown-button
          label(for="manager") Choose Pass-Request Manager   
          br
          select(name="manager") 
            option(disabled, selected) Choose Manager
            option(value="firstManager") firstManager
            option(value="secondManager") secondManager
          br
        div.text-area
          label(for="message") Compose Text in the Text-Area 
          br
          textarea(type="text" name="message" id="message" placeholder="Text here")
          br
          input(type="submit", value="submit")
              
           
              
              
      a(href="/logout") logout
    

user.js

const express = require("express");
const path = require("path");
const {handleReg,  handleLogin, handleMessage, handleLogout} = require("../controller/auth");
const {loginEng} = require("../passport/index");
const passport = require("passport");
//const local = require("../passport/local");
const {registerValidator,
       loginValidator,
       validationErrorsHandler} = require("../middleware/validator");

module.exports = function(app){
  
  app.route("/").get(function(req, res){
    res.render(__dirname + "/../views/index.pug");
  });
  
  app.route("/register").get( function(req, res){
    res.render(__dirname + "/../views/regForm.pug");
  });
  
  //ensure login helper function
  function ensureAuthentication(req, res){
    let isAuth = req.isAuthenticated();
    if(!isAuth) throw " Error authenticating login";
  };
  
  app.route("/login").get( function(req, res){
    res.render(__dirname + "/../views/login.pug");
  });
  
  app.route("/profile").get(ensureAuthentication, function(req, res){
    res.render(__dirname + "/../views/profile.pug");
  })
  
  app.route("/register").post([...registerValidator,  validationErrorsHandler], handleReg);
   
  app.route("/login").post( passport.authenticate('local', { session: false }),  handleLogin);
  
  app.route("/messages").post(function(req, res){
  const managers = {
  'firstManager': 'firstManager',
  'secondManager':'secondManager',
   // etc
}
  console.log(req.body.managers);
  res.send(req.body.managers); 
});
  
  app.route('/logout').get(handleLogout);
  
  
}    

basically i wish to get the value of firstManager/secondManager

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.