node.js - Submit form without redirect & display flash message -


i've got single page website , i'm trying submit 'subscribe newsletter' form (which has 1 input field, email) without refreshing page sending feedback using connect-flash flash messages.

right page reloads , no flash message sadly.

is there way achieve without using ajax , preventdefault method?

form

                  <div class="input-group">                       <label class="sr-only" for="subscriber-email">email address</label>                       <input name="email" type="email" id="subscriber-email" class="form-control" placeholder="email address" required>                           <span class="input-group-addon">                               <input id="subscribe-button" type="submit" class="btn btn-default" value="join">                           </span>                   </div><!--/input-grpup-->                </form>                <!-- success or error messages -->               <div id="subscription-response">                 {{#if locals.messages.success}}                   {{locals.messages.success}}                   {{/if}}               </div> 

route

 app.post('/', urlencodedparser, function(req, res){   var mailopts, smtptrans;    //send   smtptrans.sendmail(mailopts, function(error, info){     if (error) {       console.log(error);     } else {       req.flash('success', 'success message');       res.locals.messages = req.flash();       res.redirect('/');     }   }); }); 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -