#EJS Problems

1 messages · Page 1 of 1 (latest)

blissful cobalt
#

im learning ejs i started with a embed panel in bootstrap
here is my ejs part

and my server js part

app.post("/submit-form", (req, res) => {
console.log("pepe");
console.log(req.formData);
// Do something with the form data (e.g. save to database)
console.log("Form submitted successfully.");
});

idk why it logs undefined

bleak ravine
#

Console log req.body. I believe that’s what you are supposed to use to get a forms values upon a POST request.

blissful cobalt
#

just logs this stuff

#

when i do req.body its undefined

bleak ravine
#

Hmmm,

blissful cobalt
#

weird this stuff

#

XD

odd mesa
#

you don't need any of that

#

and get rid of that

visual yacht
#

Real. Just have a form action of /submit-form

blissful cobalt
visual yacht
#

Yuh. That should in theory work

blissful cobalt
#

when i submit this happens

visual yacht
#

Wrong action

blissful cobalt
visual yacht
#

<form action="/submit-form" id="embedinputs">

#

Oh

#

<form action="/sendembed" id="embedinputs" method="POST" >

blissful cobalt
#

how do i access it in te server js?

visual yacht
#

req.body

blissful cobalt
#

ok 😄

#

prints undefined

visual yacht
#

As long as all your inputs have a name attribute attached then you can access it in the req.body object

#

Eg: <input type="text" class="input input-bordered" name="name" placeholder="Type here..."required/>

blissful cobalt
chrome basin
bleak ravine
#

I didn’t even read the txt file 💀 lol

blissful cobalt
blissful cobalt
odd mesa
#
const express = require("express");
const multer = require('multer');
const bodyParser = require('body-parser');

var multerStorage = multer.memoryStorage()
app.use(multer({ storage: multerStorage }).any());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.json());
smoky isle
#

you dont need multer unless you are using multipart/form-data in the form tag which is commonly used to upload files to the server

#

also on your form tag be sure that you have the method equal to post

odd mesa
visual yacht
smoky isle
# odd mesa not sure if you're trying to educate me on something I already know or not lol. ...

Not trying to educate you, just stating the facts. He asked about using a form and req.body never once did he mention uploading files. Just telling someone to use something in this case multer when they might not need it at all is not good in anyway. For someone who seems to be learning it is also better to run into problems and ask for help rather than something working and you have no idea why.

odd mesa
visual yacht
odd mesa
#

I could have told you to google the difference between for(let item of row) and for(let item in row) but instead I just gave you a full and complete answer. Spoonfeeding is only bad if you do it for a long period of time. Asking simple questions and giving detailed answers can be far better in many situations rather than having them come across an issue and risk giving up thinking it's impossible

visual yacht
#

Me personally I like the feeling of trying to figure out problems and being close to giving up. I feel that makes people stronger, better and more independent developers

#

Thas jus me tho

smoky isle
visual yacht
#

:AYOEDP:

#

:TGTsmhDog:

odd mesa
#

This is not worth my energy

#

Aslong as it’s not PHP it’s fine

chrome basin
chrome basin
visual yacht
blissful cobalt
blissful cobalt
#

Together with bodyparser

formal silo
odd mesa
#

no

#

you are so wrong it's not even funny

#

POST requests are used to send data from form elements

#

GET requests are primarily used strictly for front-end viewing or requests that do not require you to send a body of data

#

A browser is not what is making HTTP requests, it's the client. I tell my browser what to do. It doesn't do it on it's own

#

@smoky isle Don't bother pinging me when you come in to provide the google definition for every term I've used. 💀

visual yacht