gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:34:43 26 4
gpt4 key购买 nike

我们能为 Meteor 初学者提供完整的联系表格示例吗?

到目前为止的步骤。

  • 创建架构
  • 在模板中显示联系表单
  • 确保值是通过方法传递的
  • 添加所需的包
  • 为客户端创建助手
  • 创建服务器端方法(发送电子邮件)
  • 显示成功消息

根据 https://github.com/aldeed/meteor-autoform#an-example-contact-form 上的信息进行工作

最佳答案

enter image description here

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: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cf85a0a7a18faba0aae1aca0a2" rel="noreferrer noopener nofollow">[email protected]</a>"

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: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd8e929098929398bd8e9290988a95988f98d39e9290" rel="noreferrer noopener nofollow">[email protected]</a>'
from: doc.email
subject: 'Website Contact Form - Message From ' + doc.name
text: text

关于Meteor.js + 自动形成工作联系表单示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28282310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com