Docpad : show error/success message on contact form

穿精又带淫゛_ 提交于 2019-12-24 15:46:54

问题


I added a route in my docpad.coffee file to handle form submissions, that I validate using the express-validator middleware. Now depending on the validation, I want to redirect the users to the same contact page but displaying either a success message when validation is successful (here I'll send an email), or display the error messages.

I didn't manage to pass the validation message to the template to display it. I tried almost all combinations of dynamic: true/false, res.locals = validationMessages, res.sessions = validationMessages, res.templateData = validationMessages with no success.

Furthermore, adding dynamic: true made the changes to the content not appear at all, whatever refresh strategy I use (private mode, cleaning cache, relaunching Docpad, refreshing without cache, etc.). I should probable file a bug about it.

How to ?

I'm using Docpad 6.53.0 (latest to date), node 0.10.15, on OS X 10.8.4


回答1:


I cheated on this one a bit by appending a hash to the redirect url (eg: "www.mywebsite.com/#messagesent"). I then use client side javascript to read the hash and then show the appropriate message. Something like this:

if (location.hash == "#messagesent") {  
    $('#message-sent').show();
    setTimeout(function () {
        $('#message-sent').fadeOut(1000);
    }, 1000);
}

Not quite what you were asking though :)



来源:https://stackoverflow.com/questions/19040115/docpad-show-error-success-message-on-contact-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!