Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
Form just refreshes page on submit and does not go to routes

I have been struggling with this for so long and can't figure out what the problem is. I want to just POST to /accountRoutes/editFinalMark and I have included the code for the route as well as the controller.

<form method="post" action="/accountRoutes/editFinalMark">
  <fieldset class="form-group">
    <div class="row justify-content-md-center">
      <div class="form-group" >
        <input type="" id="moduleID" name="moduleID" style="display: none;" value="<%= module._id %>">
        <input type="" name="editFinalMarkInput" id="editFinalMarkInput" class="urlInput" placeholder="Add Final Mark" style="">
      </div>
      <div class="form-group">
        <input type="submit" name="editFinalMarkButton" id="editFinalMarkButton" class="submit-docs" value="Add" style="background-color: #6dabe4; border-top-right-radius: 15px; border-bottom-right-radius: 15px; color: white;" />
      </div>
    </div>
  </fieldset>
</form>
// The Route:
router.post('/editFinalMark', accountController.editFinalMark_post);
// The Controller I want to call:
module.exports.editFinalMark_post = async (req, res) => {
    try {
        const { editFinalMarkInput, moduleID }  = req.body;

        console.log("\n\n\n\n\n");
        console.log("editFinalMarkInput: ", editFinalMarkInput);
        console.log("moduleID: ", moduleID);

        Module.findOneAndUpdate(
               { _id: moduleID }, 
               { $push: { final_mark: editFinalMarkInput } },
                 function (error, success) {
                        if (error) {
                            console.log(error);
                        } else {
                            console.log(success);
                        }
                }
        );



        res.status(201).json({  });


    } catch (err) {
        res.status(400).json({ err })
    }
};

All that happens when I click submit is that the page reloads and the url updates to include the data from the form, but it doesn't complete the action specified in the form. There are also no errors at all in the console.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

All that happens when I click submit is that the page reloads and the url updates to include the data from the form, but it doesn't complete the action specified in the form.

So it ignores both the action (because it goes to the wrong URL) and the method (because it puts the data in the URL so it is making a GET request).

From this we can infer that you have another <form> element and that is the one being submitted. You just haven't included it in the code in the question.

<form> elements aren't allowed to be nested so a validator would help you find it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda