im new and i cant get data from the form in server to insert it in the DB, heres the code:
form:
<form method = "post" action = "/register">
<label>
User Name:
<input type = "text" name = "user" onChange = {(text) => setUser(text.target.value)}></input>
</label>
<label>
Password:
<input type = "password" name = "password"></input>
</label>
<input type = "submit" name = "Send" value = "Send"></input>
</form>
and the server.js:
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const cors = require("cors");
const mongoose = require("mongoose");
const PORT = 4000;
app.use(cors());
app.use(bodyParser.json());
mongoose.connect("mongodb://127.0.0.1:27017/Cook", {
useNewUrlParser: true,
});
const connection = mongoose.connection;
app.post("/register", function(request, response) {
let user = request.body.user;
let password = request.body.password;
console.log(user)
})
if anyone can help, would appreciate it :)
The issue is your are wrapping input field in label. I have updated the code below:
<form method="post" action="/register">
<label>User Name:</label>
<input type = "text" name = "user" value="keep any default if needed">
<label> Password:</label>
<input type = "password" name = "password">
<input type="submit" value="Send" >
</form>
You need to explicitly enable this to parse form's data.
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
So , I'm using HTML , css and JavaScript, I did a form , where the user will give different data, like name , adress , ID number , etc and I want to introduce those values into a preformatted text (like a renting contract)
I am trying to create when user check checkbox to yes(true) in Index Page Emergency column needs to flash text something like Emergency But unfortunately I try couple of methods but unsuccessfullyHere is so far what I did
if I have a query that looks like this in php