防止MeteorJS集合中的重复(通过表单)
Prevent Duplicity (through form) in MeteorJS collection
我正在通过表单收集数据&使用输入类将其保存到流星集合(工作正常)。现在我想防止重复输入"电子邮件"&"类别"组合(用户不能两次从同一封电子邮件申请类别)。请帮忙
还告诉我如何生成在表格中填写姓名的感谢通知
/*Meteor JS File*/
Info = new Meteor.Collection("info");
if (Meteor.isClient) {
Template.add_info.events({
'submit form':function(){
Info.insert({
category:$('.the_item11').val(),
name:$('.the_item1').val(),
mobile:$('.the_item2').val(),
Mail:$('.the_item3').val(),
createdAt: new Date(),
});
if ($.trim($("#uname").val()) === "" || $.trim($("#umobile").val()) === ""){
alert('you did not fill out one of the fields');
return false; }
alert("Thank You For Registering")
}
});
}
/*HTML form*/
<head>
<title>yahaviform</title>
</head>
<body>
<img src="EDMcrowd.jpg" name="CA_5" id="CA_5"/>
<h1 id="reg">Register here</h1>
{{> add_info}}
</body>
<template name="add_info">
<div id="d1">
<form>
<label>You are</label><br>
<select class="the_item11" id="ucat" required>
<option></option>
<option>DJ</option>
<option>Singer</option>
<option>Instrumentalist</option>
<option>Band</option>
</select> <br>
<label>Name</label><br>
<input type="text" class="the_item1" id="uname" required><br>
<label>Mobileno.</label><br>
<input type="tel" class="the_item2" id="umobile" required><br>
<label>EmailID</label><br>
<input class="the_item3" type="email" id="umail" required><br>
<br>
<input type="submit" value="Register">
</form>
</div>
</template>
您可以使用复合唯一索引:
db.my_collection.ensureIndex(
{
email: 1,
category: 1
},
{
unique: 1
}
)
看看很棒的包meteor-autoform
https://github.com/aldeed/meteor-autoform
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如何使用WCF服务和javascript表单post上传.doc文件
- Javascript生成的表单未提交
- 如何使用javascript或html下载PDF格式的填写表单
- HTML表单提交时未执行外部函数
- 如何将输入(type=text)从html表单传递到javascript函数
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- Ajax发布表单序列化,发布引号'
- 多级HTML表单
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 在验证和发送邮件后更改联系人表单的 html
- jQuery表单添加不适用于下拉列表
- Rails/JSON:如何将JSON用于jquery UI自动完成表单
- 如何从pdftron webviewer获取表单数据
- JS验证ajax返回的html中的表单数据
- 防止MeteorJS集合中的重复(通过表单)
- MeteorJS电子邮件表单验证
- 如何使用Astronomy-MeteorJS使用父属性验证表单
- 在Meteorjs中重用表单
- 用IronRouter / MeteorJS在Bootstrap模式中提交表单