1

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.

2
  • You can either save state in server, save fields with localStorage or pass data as url params. Plenty of ways to do it Commented May 14, 2016 at 1:34
  • @juvian which way do you think is the most efficient? Commented May 14, 2016 at 1:52

2 Answers 2

3

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
        }
    });
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

Much better solution will be to maintain a session object using reactive-var. May it be n forms, you can simply update session object. In above code what if user goes back and make changes to first form? It will again insert or may even fail. Above code just shows positive work flow, but you have to consider all possibilities. You can do all n updates to session object, which don't matter. The db call is made to last form where you insert just once and you are done. Before accepting a solution you should throughly examine the usecases fullfilled by an answer.

2 Comments

I would totally do that but I am not that familiar on the subject. Do you have a good website that might explain what a reactive-var is?
when you create a meteor project, by-default it has a count variable set as active variable, when you click it, it increments. that itself is an example. on top of that you refer to hint code below.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.