Die Daten aus dem Formular werden nicht in der Konsole gedruckt, sondern werden per Post-Express-Methode erfasstHTML

HTML-Programmierer
Anonymous
 Die Daten aus dem Formular werden nicht in der Konsole gedruckt, sondern werden per Post-Express-Methode erfasst

Post by Anonymous »

Ein Formular befindet sich auf der Admin-Seite zum Hinzufügen von Produkten, aber die Daten (die Daten umfassen eine Bilddatei) im Formular werden nicht in der Konsole gedruckt, stattdessen wird Folgendes angezeigt:

"{}

POST /admin/add-product - - ms - -"

Hier ist der Code der app.js (Express-Generator)

Code: Select all

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var hbs = require('express-handlebars')
var usersRouter = require('./routes/users');
var adminRouter = require('./routes/admin');
var fileUpload = require('express-fileupload')

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.engine('hbs', hbs.engine({ extname: 'hbs', defaultLayout: 'layout', layoutsDir: __dirname + '/views/layout/', partialsDir: __dirname + '/views/partials/' }))

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', usersRouter);
app.use('/admin', adminRouter);
app.use(fileUpload())

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
Hier sind die Codes in der Admin-Datei

Code: Select all

var express = require('express');
var router = express.Router();

/* GET users listing.  */
router.get('/', function(req, res, next) {
let products=[{
name:"Iphone 15"
,category:"Mobile"
,discription:"flaghship phone by apple"
,image:"https://encrypted-tbn1.gstatic.com/shopping?q=tbn:ANd9GcR199XXubeTzwSceNjVSDZLSmAS9XKBkftsUbcSGADAGYXqqDRs17BYcd3jocTU_xeenejYWbzJbs394WBFqKBZOwJJcI3il9Pmcz8d3bA&usqp=CAE"

},{
name:"Samsung Galaxy S23 ultra"
,category:"Mobile"
,discription:"flaghship phone by Samsung"
,image:"https://encrypted-tbn0.gstatic.com/shopping?q=tbn:ANd9GcQ3uCOtqrOC3OSc1mveQKwrFN4bBVPsOk5FhSznuH-9bZMOU4qHs_-FYJscJ8nFGLDDZ3a_Cla-HCiHjkik3CaBRgsarJ-ZDKErAyLMLe2VRNBIeU1sti7Q&usqp=CAE"

},{
name:"Nothing phone 2"
,category:"Mobile"
,discription:"flaghship phone by NOthing"
,image:"https://encrypted-tbn0.gstatic.com/shopping?q=tbn:ANd9GcQvcN7cV_G4iXn6uy8_RoByjPj35Vh1MA0nDKFdg6YNep0EzLTbTsV40YqO1tKxxjFQl8DFOfDW1-vOFTEikA_ZdlrWh9WDwHeFIln0xDuuy2BQRp2wcl4ZTw&usqp=CAE"

},{
name:"MI 13 ultra"
,category:"Mobile"
,discription:"flaghship phone by apple"
,image:"https://encrypted-tbn0.gstatic.com/shopping?q=tbn:ANd9GcTv3moXySHfJ_y7ZuoC7S2gxrA2wWtvOe9Zw-YQiwX59uIBkR4IlZuptO9ThOnFiUGLSwpQjcOI8m0LCY19RMWJBcEn66jj_TioDlxIKCJgIekD60awjBYLIg&usqp=CAE"

}]

res.render('admin/view-products',{admin:true,products})
});
router.get('/add-product',function(req,res){

res.render('admin/add-product',)
})

router.post('/add-product',(req,res)=>{
console.log(req.body);
})

module.exports = router;
Hier ist die Form von HTML-Codes

Code: Select all

    




Add Product

Name


Category


Price


Discription


Image


submit





Ich möchte, dass die Daten in der Konsole mit der IMG-Datei gerendert werden

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post