Meteor.js+;自动形成工作联系人表单示例

Meteor.js+;自动形成工作联系人表单示例,meteor,Meteor,我们能为流星初学者提供一个完整的联系方式示例吗 到目前为止的步骤。 创建模式 在模板中显示联系人表单 确保使用方法传递值 添加所需的包 为客户端创建帮助程序 为服务器端创建方法(发送电子邮件) 显示关于成功的消息 从上的信息工作 两者/收藏/联系。咖啡 @Contacts = new Meteor.Collection('contacts') Schemas.Contacts = new SimpleSchema name: type: String label: "Y

我们能为流星初学者提供一个完整的联系方式示例吗

到目前为止的步骤。

  • 创建模式
  • 在模板中显示联系人表单
  • 确保使用方法传递值
  • 添加所需的包
  • 为客户端创建帮助程序
  • 为服务器端创建方法(发送电子邮件)
  • 显示关于成功的消息
从上的信息工作

两者/收藏/联系。咖啡

@Contacts = new Meteor.Collection('contacts')

Schemas.Contacts = new SimpleSchema
  name:
    type: String
    label: "Your name"
    max: 50
    optional: true
    autoform:
      placeholder: "John Doe"

  email:
    type: String
    regEx: SimpleSchema.RegEx.Email
    label: "E-mail address"
    optional: true
    autoform:
      placeholder: "John@doe.com"

  message:
    type: String
    label: "Message"
    max: 1000
    optional: true
    autoform:
      placeholder: "Message"
      rows: 3

Contacts.attachSchema(Schemas.Contacts)
if Meteor.isClient
  Template.contactPage.helpers
    contactFormSchema: ->
      Schemas.Contacts
if Meteor.isServer
  Meteor.methods
    sendEmail: (doc) ->
    # Important server-side check for security and data integrity
    check doc, Schemas.contacts
    # Build the e-mail text
    text = 'Name: ' + doc.name + '\n\n' + 'Email: ' + doc.email + '\n\n\n\n' + doc.message
    @unblock()
    console.log "about to send the email"
    # Send the e-mail
    Email.send
      to: 'someone@somewhere.com'
      from: doc.email
      subject: 'Website Contact Form - Message From ' + doc.name
      text: text
查看/contact/contact.html

<template name="contactPage">
  <h2>Get in Contact</h2>
  {{> quickForm
    schema=contactFormSchema
    id="contactForm"
    type="method"
    meteormethod="sendEmail"
    template="bootstrap3-horizontal"
    label-class="col-sm-3"
    input-col-class="col-sm-9"
  }}
</template>
查看/联系/联系。咖啡

@Contacts = new Meteor.Collection('contacts')

Schemas.Contacts = new SimpleSchema
  name:
    type: String
    label: "Your name"
    max: 50
    optional: true
    autoform:
      placeholder: "John Doe"

  email:
    type: String
    regEx: SimpleSchema.RegEx.Email
    label: "E-mail address"
    optional: true
    autoform:
      placeholder: "John@doe.com"

  message:
    type: String
    label: "Message"
    max: 1000
    optional: true
    autoform:
      placeholder: "Message"
      rows: 3

Contacts.attachSchema(Schemas.Contacts)
if Meteor.isClient
  Template.contactPage.helpers
    contactFormSchema: ->
      Schemas.Contacts
if Meteor.isServer
  Meteor.methods
    sendEmail: (doc) ->
    # Important server-side check for security and data integrity
    check doc, Schemas.contacts
    # Build the e-mail text
    text = 'Name: ' + doc.name + '\n\n' + 'Email: ' + doc.email + '\n\n\n\n' + doc.message
    @unblock()
    console.log "about to send the email"
    # Send the e-mail
    Email.send
      to: 'someone@somewhere.com'
      from: doc.email
      subject: 'Website Contact Form - Message From ' + doc.name
      text: text
服务器/联系发送咖啡

@Contacts = new Meteor.Collection('contacts')

Schemas.Contacts = new SimpleSchema
  name:
    type: String
    label: "Your name"
    max: 50
    optional: true
    autoform:
      placeholder: "John Doe"

  email:
    type: String
    regEx: SimpleSchema.RegEx.Email
    label: "E-mail address"
    optional: true
    autoform:
      placeholder: "John@doe.com"

  message:
    type: String
    label: "Message"
    max: 1000
    optional: true
    autoform:
      placeholder: "Message"
      rows: 3

Contacts.attachSchema(Schemas.Contacts)
if Meteor.isClient
  Template.contactPage.helpers
    contactFormSchema: ->
      Schemas.Contacts
if Meteor.isServer
  Meteor.methods
    sendEmail: (doc) ->
    # Important server-side check for security and data integrity
    check doc, Schemas.contacts
    # Build the e-mail text
    text = 'Name: ' + doc.name + '\n\n' + 'Email: ' + doc.email + '\n\n\n\n' + doc.message
    @unblock()
    console.log "about to send the email"
    # Send the e-mail
    Email.send
      to: 'someone@somewhere.com'
      from: doc.email
      subject: 'Website Contact Form - Message From ' + doc.name
      text: text

当前代码导致出现错误。传递调用“sendEmail”的结果时出现异常:错误:匹配失败[400]我希望看到一个同时保存文档的联系人表单。也许这不被认为是一个联系表单,但将表单保存到db然后发送某种通知似乎是相当标准的。