Reputation: 506
Can we get a complete contact form example for Meteor beginners?
The steps so far.
Working from the info on https://github.com/aldeed/meteor-autoform#an-example-contact-form
Upvotes: 2
Views: 1772
Reputation: 506
both/collections/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: "[email protected]"
message:
type: String
label: "Message"
max: 1000
optional: true
autoform:
placeholder: "Message"
rows: 3
Contacts.attachSchema(Schemas.Contacts)
views/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>
.meteor/packages
coffeescript
aldeed:collection2
aldeed:simple-schema
aldeed:autoform
twbs:bootstrap
email
views/contact/contact.coffee
if Meteor.isClient
Template.contactPage.helpers
contactFormSchema: ->
Schemas.Contacts
server/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: '[email protected]'
from: doc.email
subject: 'Website Contact Form - Message From ' + doc.name
text: text
Upvotes: 5