Docpad:在联系表单上显示错误/成功消息 [英] Docpad : show error/success message on contact form

查看:67
本文介绍了Docpad:在联系表单上显示错误/成功消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在docpad.coffee文件中添加了一条处理表单提交的路由,并使用 express-验证程序中间件.现在,根据验证,我想将用户重定向到相同的联系页面,但是在验证成功后显示成功消息(在此我将发送电子邮件),或显示错误消息.

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.

我没有将验证消息传递给模板以显示它.我尝试了dynamic: true/falseres.locals = validationMessagesres.sessions = validationMessagesres.templateData = validationMessages的几乎所有组合,均未成功.

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.

此外,添加dynamic: true使得对内容的更改根本不会出现,无论我使用什么刷新策略(私有模式,清理缓存,重新启动Docpad,刷新而不缓存等).我应该提交有关此问题的错误.

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.

如何?

我正在OS X 10.8.4上使用Docpad 6.53.0(最新),节点0.10.15

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

推荐答案

我通过将哈希值附加到重定向网址(例如:"www.mywebsite.com/#messagesent")上对此作了一点欺骗.然后,我使用客户端javascript读取哈希,然后显示适当的消息.像这样:

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 :)

这篇关于Docpad:在联系表单上显示错误/成功消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆