dylan dylan - 6 months ago 9
HTML Question

How do you get user input for a mongo db document from multiple different html pages?

I have a mongodb setup that will hold some user input values. The forms where the user will input data are all on different html pages, once you fill out one, it will send you to the next page. What I cannot figure out is how to put all this data into one document once every field has been filled. I find this complicated because if you go to the next page for the next form, that previous form will not just hold the data waiting for all the other forms to be filled out. To put this in some context, I am using meteor and the packages aldeed:autoform and aldeed:collection2 to have user input transformed into a json format document. At the moment, I can only have all the user input filled out on the same page using autoform then press the submit button for it all to be put on a document at the same time.

Answer

On the first form insert to a collection with the Meteor.userId() (assuming your users are logged in). On the next forms you can simply update the collection using methods.

Client:

Meteor.call('firstForm',var1,var2);
Meteor.call('secondForm',var1,var2);

Server:

Meteor.methods({
  'firstForm': function (var1,var2) {
    collection.insert({
      createdBy: Meteor.userId(),
      var1: var1,
      var2: var2
    });
  },
  'secondForm': function (var3,var4) {
    collection.update({
      createdBy: Meteor.userId()
    }, {
        $set: {
            var3: var3,
            var4: var4
        }
    });
  }
});
Comments