Slip22 Using node js create an Employee Registration Form validation.

index.html 

<!DOCTYPE html>

<html>

<head>

<title>Employee Registration</title>

</head>

<body>

<h1>Employee Registration Form</h1>

<form action="/register" method="post">

<label>Name:</label><br>

<input type="text" name="name" required><br>

<label>Email:</label><br>

<input type="email" name="email" required><br>

<label>Password:</label><br>

<input type="password" name="password" required><br>

<input type="submit" value="Register">

</form>

</body>

</html>


slip22.js

const http = require('http');

const fs = require('fs');

const qs =require('querystring');

const server = http.createServer((req, res) => {

if (req.method === 'GET' && req.url === '/') {

// Serve HTML form

fs.readFile('index.html', (err, data) => {

if (err) {

res.writeHead(500);

res.end('Internal Server Error');

return;

}

res.writeHead(200, { 'Content-Type': 'text/html' });

res.end(data);

});

} else if (req.method === 'POST' && req.url === '/register') {

// Handle form submission

let body = '';

req.on('data', chunk => {

body += chunk.toString();

});

req.on('end', () => {

const formData =qs.parse(body);

const name = formData['name'];

const email = formData['email'];

const password = formData['password'];


// Basic form validation

if (!name || !email || !password) {

res.writeHead(400);

res.end('Please fill out all fields');

} else {

// If validation passes, process registration

res.writeHead(200);

res.end('Registration successful!');

}

});

} else {

// Handle other routes

res.writeHead(404);

res.end('Not Found');

}

}).listen(3032, () => {

console.log('Server is running on port 3032');

});

Comments

Popular posts from this blog

Slip 11: Write node js application that transfer a file as an attachment on web and enables browser to prompt the user to download file using express js.

Slip 7 Create a node js file named main.js for event-driven application. There should be a main loop that listens for events, and then triggers a callback function when one of those events is detected.

Slip 1(a) Write an Angular 13 application addition of two numbers using ng-init, ng-model & ng-bind. And also demonstrate ng-show, ng-disabled, ng-click directives on button component.