Skip to content

Instantly share code, notes, and snippets.

@anmolsukki
Last active February 14, 2021 06:48
Show Gist options
  • Save anmolsukki/899c3aaf55b7b2e72c3cdbb36bd94bc9 to your computer and use it in GitHub Desktop.
Save anmolsukki/899c3aaf55b7b2e72c3cdbb36bd94bc9 to your computer and use it in GitHub Desktop.
[Method Post] Data Post in HTML Form

Post method Html Form

.App {
text-align: left;
width: 50%;
margin: auto;
}
input[type='text'],
select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type='submit'] {
width: 100%;
background-color: #4caf50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type='submit']:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<title>Method Post</title>
</head>
<body class="App">
<form action="/myaction" method="post">
<label for="name">Name</label>
<input type="text" id="name" name="name" value="Anmol Kumar Singh" placeholder="Your name">
<label for="mobileNumber">Mobile Number</label>
<input type="text" id="mobileNumber" name="mobileNumber" value="9878986993" placeholder="Mobile Number">
<label for="emailId">Email ID</label>
<input type="text" id="emailId" name="emailId" value="anmolsukki94.com" placeholder="Email ID">
<label for="uniqueId">Unique ID</label>
<input type="text" id="uniqueId" name="uniqueId" value="123456" placeholder="Unique ID">
<button type="submit">Submit</button>
</form>
</body>
</html>
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/myaction', function(req, res) {
res.send('You sent the name "' + req.body.name + 'You sent the name "' + req.body.mobileNumber + '".');
});
app.listen(8000, function() {
console.log('Server running at http://127.0.0.1:8080/');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment