使用表单上的表单上传图片提交

时间:2015-05-08 03:45:17

标签: forms meteor

我正在尝试创建一个简单的网络应用,要求用户填写几个问题,然后上传照片。我希望在按下提交按钮时将所有这些信息存储在Meteor集合中,但是我对FS Collection包有些困难。

以下是相关的main.html:

    <form class="photoForm">
    Problem: <input type = "text" id = "problem" placeholder="page # problem #"><br><br>
    Your group members <input type = "text" id="group" size="50"> <br><br>
    Your questions and comments about this problem: <br><br>
    <textarea name="comments" form="photo" rows="4" cols="70" placeholder="Enter text here..."></textarea>
    <br>

    Upload a snapshot of your work here: <input type = "file" id = "myFileInput">
    <br /><br />

    <input type="submit" value="submit" />
    </form>

这是main.js:

Template.form.events({ 
'click input[type=submit]': function(event, template) {

console.log("form submit")
event.preventDefault();

FS.Utility.eachFile(event, function(file) {


  Images.insert(file, function (err, fileObj){
    //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
  });

});
 }   
});

以下是我的问题:

  1. 我只能在事件'change .myFileInput'上获取要上传的文件。我试图让它上传'点击输入[type = submit]'和'submit',它不会上传文件。有没有办法让它在单击提交按钮时上传文件?

  2. 如何将各种文本字段中的数据添加到图像集合中?我可以将这些添加内容合并到Images.insert()命令中吗?

1 个答案:

答案 0 :(得分:2)

检查autoform包

autoform package

和cfs autoform包 Cfs autoform

这些套餐非常有用

相关问题