Unable to handle a POST request initiated by an HTML Form

Recently, I started working with Express and Bootstrap. While attempting to create a login form that triggers a POST request to the server, I encountered an issue where the page displays "The page isn't working" instead of loading a new HTML page.

Here is the structure of my HTML form:

<section class="h-100">
<div class="container h-100" style="margin-top: 50px; ">
<div class="row justify-content-md-center h-100" >
<div class="card-wrapper">
<div class="card fat">
<div class="card-body">
<h3 class="card-title">Login</h3>
<form method="POST" class="my-login-validation" novalidate="">
<div class="form-group">
<label for="email">E-Mail Address</label>
<input id="email" type="email" class="form-control" name="email" value="" required autofocus>
<div class="invalid-feedback">
Email is invalid
</div>
</div>

<div class="form-group">
<label for="password">Password
</a>
</label>
<a href="forgot.html" style="float: right">
Forgot Password?
</a>
<input id="password" type="password" class="form-control" name="password" required data-eye>
<div class="invalid-feedback">
Password is required
</div>
</div>


<div class="form-group m-0">
<button type="submit" class="btn btn-primary btn-block">
Login
</button>
</div>

</form>
</div>
</div>
</div>
</div>
</div>
</section>

This is how I set up my Express to respond to the form submission by sending a new html page:

router.post("/index.html", function(req, res, next){
   res.send(`
  <!DOCTYPE html>
  <html lang='en'>
  <head>
          <meta charset="UTF-8">
        <title>Practical Excercise 3 - Part 3</title>
  </head>
  <body>
    <p> Payment Received </p>
  </body>
  </html>
  `);
});

Despite setting it up this way, when I click the login button in the HTML form, the POST request fails to return a new HTML page as intended. If anyone can point out where the problem lies, I would greatly appreciate it! Thank you all!

Answer №1

Don't forget to boot up the server with npm start

Wishing you a fantastic day!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the steps to convert an image to base64 while circumventing the restrictions of the same-origin policy

I've been struggling to convert an image link to base64 in order to store it on the client-side browser (IndexedDB). Despite searching for a solution for days, I have not been able to find one that addresses my issue. While I can successfully convert ...

Strange behavior in Internet Explorer when using jQuery to simulate a click on an input=file element

My customized jQuery and HTML code achieves the following purpose: There is a placeholder image that can be clicked by the user, triggering a file selection dialog to open. Once a file is chosen, the corresponding multipart form is sent to the server. To ...

What is the best way to integrate the EJS view engine into a setup with Express and Webpack Dev Server?

I am currently facing an issue while trying to integrate ejs into a project that uses express and webpack dev server. The problem I am encountering is that even though I am passing my variables correctly, they are being loaded in this manner: Html Webpack ...

Unlock the power of VueJS with advanced checkbox toggling for array data

I have encountered an issue while working with VueJS regarding the implementation of two features for a set of checkboxes. Initially, the checkboxes are generated dynamically. I am in need of a master 'toggle' checkbox that can toggle the stat ...

CSS ratings bar styling

Looking to create a unique ratings bar for my website, I have some questions that need answering. Take a look at the codepen link to see what I've come up with so far. My main query is about incorporating two different colors for Likes (green) and Di ...

Is it time to reconsider saving sessions in Node.js?

Here is the provided code snippet: app.get('/vklogin', function(request, response) { console.log('Authorizing via "Vk.com" social network'.green); var url_parts = url.parse(request.url, true); var query = url_parts.query; var data = q ...

What is the best method to "deactivate" a radio button while ensuring that a screen reader can still read the text and notify the user that it is inactive?

My current situation involves needing to deactivate certain radio buttons, while still having the option to reactivate them later. When I use the disabled attribute, screen readers will overlook this field and miss key information. I am seeking an accessi ...

Choose a child using react material ui's makeStyles

Currently utilizing React and Material UI, I am attempting to use the nth-child selector with the MUI makeStyle function. However, it is not working as expected. Here are some screenshots for reference: https://i.sstatic.net/5dVhV.png https://i.sstatic.ne ...

Assign and retrieve unique identifiers for checkboxes

One of the challenges I'm facing is working with an array of ID's from a database in combination with a table layout: The ID array includes specific record identifiers, for example: Array ( [0] => Array ( [id] => 1 [code] => GHY87 [de ...

Adjusting image size by adding padding to accommodate larger screens using Bootstrap 4

I have incorporated Bootstrap into my server-side web application to resize images for larger screens by adding padding to prevent them from getting too big. However, I'm unsure if this is the best approach. Are there better methods for resizing image ...

Turn off ETAG for JSON responses, while turning on ETAG for static assets

Within our Express middleware configuration, we are utilizing the code snippet: app.enable('etag'); An issue has arisen where JSON requests are receiving a 304 status code when they should actually be re-evaluated or resent. My inquiry is cen ...

Are there any real-world examples you can share of utilizing CSS 3D Transforms?

Can you provide any instances of CSS 3D Transforms being utilized in real-world projects besides and ? ...

Encountering a SyntaxError: Unexpected token '?' error while utilizing the 'express-rate-limit' package

I am encountering an issue while trying to implement 'express-rate-limit' in my code. Strangely, when I run the server, I receive a SyntaxError: Unexpected token '?', even though I have double-checked that there are no syntax errors in ...

Node.js encountering issue with printing an array

Here is the code snippet from my routes file: router.get('/chkjson', function(req, res, next) { req.getConnection(function(err,connection){ var ItemArray = []; var myset = []; var query = connection.query('SELEC ...

What steps should I follow to create my production-ready Express backend?

I just finished developing an Express Server. What steps do I need to take in order to prepare it for deployment on a WebApp? Unfortunately, my project does not contain any build scripts. ...

Implementing SSL certificate for MongoDB with Mongoose and Express

I'm having trouble figuring out how to add an SSL certificate to my server.js in order to access my API on the server through https. var express = require('express'), cors = require('cors'), app = express(), port = pro ...

Using an array of images with CSS and displaying them in HTML

Is there a way to use one class for 3 buttons, each with its own unique background image? I wanted to create an array of background images in CSS and then retrieve them individually for each button. However, after some research, it seems that CSS does not ...

Make sure to pause and wait for a click before diverting your

Having an issue with a search dropdown that displays suggestions when the search input is focused. The problem arises when the dropdown closes as soon as the input loses focus, which is the desired functionality. However, clicking on any suggestion causes ...

Tag editor assessing the input's width for SO

I've been working on a tag editor similar to Stack Overflow's and it's coming along nicely. The only issue I'm facing is calculating the width of the textbox after a tag has been selected by the user. For each tag added, I try to adjus ...

Using Windows 10 to hot reload a Node app in Docker with nodemon

I am currently working on an express app and attempting to implement hot reloading with nodemon using docker in a windows 10 development environment. However, I am encountering an issue where hot reloading does not seem to work after npm install on the vol ...