我们可以获得Meteor初学者的完整联系表单示例吗?
到目前为止的步骤。
使用https://github.com/aldeed/meteor-autoform#an-example-contact-form
上的信息答案 0 :(得分:5)
<强>两者/集合/ contact.coffee 强>
@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)
<强>视图/接触/ 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>
<强> .meteor /包强>
coffeescript
aldeed:collection2
aldeed:simple-schema
aldeed:autoform
twbs:bootstrap
email
<强>视图/接触/ contact.coffee 强>
if Meteor.isClient
Template.contactPage.helpers
contactFormSchema: ->
Schemas.Contacts
服务器/ contact-send.coffee 强>
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