Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:30:06+00:00 2026-06-04T06:30:06+00:00

Using node.js and express (2.5.9) with express-form. How should I repopulate form fields with

  • 0

Using node.js and express (2.5.9) with express-form.

How should I repopulate form fields with the submitted values?

I have a get and a post route. If there are validation errors when the form is posted, I redirect the user back to the get, the problem is that the repopulated locals don’t show up (I do have autoLocals: true, so I assume it’s because I am redirecting and res is reset.)

So how do you guys repopulate and what’s your application flow, do you res.send instead of res.redirect and set up the whole thing again? That seems repetitive.

Here’s an example of my post route:

app.post(

  '/projects/:id'

  , form(field("title").required("title", "Title is required)
  , function (req, res){

  if (!req.form.isValid){
    res.redirect('/project/'+req.params.id+'/edit');
  }
  else{
    // save to db
  }

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:30:08+00:00Added an answer on June 4, 2026 at 6:30 am

    Not sure if it’s best practice, but when I have validation failure, I don’t redirect I just re-render the view (often by passing control to the ‘get’ callback). Somethign like this:

    function loadProject(req,res, id){ /* fetch or create logic, storing as req.model or req.project */} 
    
    function editProject(req,res){ /* render logic */ }
    
    function saveProject(req,res){ 
        if(!req.form.isValid){ 
            editProject(req,res);
        }else{
            saveToDb(req.project);
            res.redirect('/project'+req.project.id+'/edit');
        }
    }
    
    app.param('id', loadProject);
    app.get('/projects/:id/edit', editProject);
    app.post('/projects/:id', saveProject);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
I have a Node.js Express app that I'm hosting on Nodejitsu. I'm already using
I'm using node, express and connect for a simple app and have basic HTTP
I have built my application using node.js, mongodb, redis, express, socket.io and planning to
I start to look at Node.js. Also I'm using Express. And I have a
I am building an app on node.js using express, and node-mysql driver. There is
I'm using Node.JS and Express web framework, I have a problem with the res.render()
I am using node.js + express.js + everyauth.js. I have moved all my everyauth
I have the following in my node server using Express (truncated to the important
I have managed to get file uploading work in Node.js with Express, and in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.