Why-Assumptions-How-Troubleshooting
留言发送mail
1、首先配置 dispatch 这里应该是webmachine(还没具体看), 在此确定了url和模板
{contact_url, ["contact"], resource_template, [ {template, "contact.tpl"} ]},
2、创建模板,添加适当的内容即可。这里的wire很关键,目前还完全明白。
注意delegate="resource_default_contact",这个与下面的 resource_default_conatact对应
{% wire id="contact-form" type="submit" postback={contact} delegate="resource_default_contact" %} <form id="contact-form" method="post" action="postback"> <label for="name">Name</label> <input type="text" name="name" id="name" /> <label for="email">E-mail</label> <input type="text" name="mail" id="mail" /> {% validate id="mail" type={presence} type={email} %} <label for="message">Message</label> <textarea name="message" id="message" cols="60" rows="8"></textarea> {% validate id="message" type={presence} %} <input type="submit" value="Send" /> </form>
3、在priv/sites/default/resources/resource_default_contact.erl 创建
-module(resource_default_contact). -export([event/2]). -include_lib("zotonic.hrl").event({submit, {contact, []}, _TriggerId, _TargetId}, Context) -> Vars = [{mail, z_context:get_q("mail", Context)}, {name, z_context:get_q("name", Context)}, {message, z_context:get_q("message", Context)}], z_email:send_render(z_email:get_admin_email(Context), "_email_contact.tpl", Vars, Context), z_render:update("contact-form", "<p>The form has been submitted! Thank you, we'll get in touch soon.</p>", Context).
4、在添加 priv/sites/default/templates/_email_contact.tpl:模板
主要是配置URL\创建模板\创建处理event事件的resource
详细见来自官方的例子http://zotonic.com/documentation/807/implementing-a-simple-contact-form