1

I'm following a tutorial to learn Nodejs and the framework express.js. In this tutorial, I installed a front from node and linked it to my backend. I don't edit my front because it is in my node_modules but I want to get informations from a form. I use the following code to get informations from the form :

app.post('/api/stuff', (req, res, next) => {
    console.log('test');
    console.log(req.body);
    res.status(201).json({
        message: 'Objet créé !'
    });
});

When I submit data from the form, I get any return and this error message in the console :

Form submission canceled because the form is not connected

I do not understand why I don't get any data from the form.

Can someone help me please?

Maratrom
  • 11
  • 1
  • This will help you https://stackoverflow.com/questions/42053775/getting-error-form-submission-canceled-because-the-form-is-not-connected – Alexandru DuDu Apr 13 '22 at 15:01
  • Does this answer your question? [Getting Error "Form submission canceled because the form is not connected"](https://stackoverflow.com/questions/42053775/getting-error-form-submission-canceled-because-the-form-is-not-connected) – Alexandru DuDu Apr 13 '22 at 15:01

1 Answers1

1

Check if you already doing input parsing using body-parser(npm module) Ref Link : http://expressjs.com/en/resources/middleware/body-parser.html

Eg(code):

var express = require('express')
var bodyParser = require('body-parser')

var app = express()

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

// after above parsing 
app.post('/api/stuff', (req, res, next) => {
    console.log('test');
    console.log(req.body); // after parsing req.body will be json , from front end we need not to stringify and do other stuff
    res.status(201).json({
        message: 'Objet créé !'
    });
});