Doubt/problem redirecting after form submission with Node.js

Asked

Viewed 56 times

0

Well, I’m new to programming and I’m trying to make a prototype of frequency recording to learn a little bit more about how to handle the database. My application has an area that I can be visualizing all the posts and adding more precise case (may be visualizing all the students), I used some logics to be creating rooms and thus showing only the students who are in the classrooms, that is, a filter so that each student appears only in your classroom. Let’s get to my problem, so that this was possible I performed some logics where basically I took the URL of the generated page and included in the filter, so I showed only those students from a certain room (I still could not be performing the relationship/association of tables). With this, as the method of inserting the post is the same, I used the same app.post code to be including the data in the table as in the part where it showed everything and how much in the part where it showed with filters, where basically I can not be redirecting to the same page of form, as they may present the same page but with the filters I am showing in the options only the students of the class.

This image below shows the form without filter, that is, it can be included the presence for the student in any room (presence = post) (URL: http://localhost:8081/Cad?)

The other image shows the form with the filter, as you can see the student is from room two and can only be included in room two. (URL: http://localhost:8081/Postpro/sala2?)

With this comes the problem, because to trigger the post:

 app.post('/addPost', function(req, res){
        Post.create({
            titulo: req.body.titulo, //seria o horário
            conteudo: req.body.conteudo, // seria o nome do aluno
            sala: req.body.sala
        }).then(function(){
            res.redirect()
        }).catch(function(erro){
            res.send("Houve um erro: "+erro)
        })
    })

it is being redirected to a single page, but also can’t (if possible, I’m sorry) be picking up the url of the page with filter, because it was formed with some req.params, so every time I send the fomulário I am redirected to a page, but I was wondering if it’s possible after sending the form I’m staying on the same page.

Note: I am using Mysql, sequelize, Node.js, handlebars and some Avascripts for this.

I removed the res.redirect() but the page is just loading, this would be a solution for now, but it is something strange to see, It would have as tidying or putting otherwise?

  • Cara was very confused his question, I didn’t really understand, but from what I read he’s having trouble getting the parameters of the url. To start giving you a light, you can take the parameters with req.params

  • yes, I am doing this, I use params to filter the data, after that I am using same app.post to add posts, but when adding is redirected to another page, which are two different pages, I just wanted to know if there is no way to be redirected to any page, IE, keep in the form page that is at the moment.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.