W
W
websjunior2017-02-12 08:20:12
Node.js
websjunior, 2017-02-12 08:20:12

There are 4 forms on the page for submitting data. How to process only one form in nodejs when clicking on a button in the desired form?

There are 4 forms. She is different. But when you click, all forms on this page will be processed. How to do that only the necessary one was processed. On php it was easier there was just an ISSET function.

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

/* GET home page. */
router.get('/', function(req, res, next) {
  	res.render('index', { title: 'Главная'});
});

/* POST home page. */
router.post('/', function(req, res, next) {
  res.send("modal=1");
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2017-02-12
@websjunior

<form>
  <input type='hidden' name='action' value='form_one'>
</form>

router.post( '/', function( req, res, next ) {
  if ( req.body.action === 'form_one' ) {...}
});

I
Ivan, 2017-02-12
@LiguidCool

htmlbook.ru/html/form
Attention to attributes (name in particular).
Besides it is possible to conjure with action.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question