简体   繁体   English

流星:构建自定义表单,提交后需要帮助重定向

[英]Meteor: Building a custom form and need help redirecting after submission

EDIT: I did add action="/results" to the form element but it does not do anything. 编辑:我确实添加了action="/results"到表单元素,但它没有做任何事情。 I also set the page /results on my routes. 我还在路线上设置了/results页面。

New to Meteor and I'm working on a app that collect form entries for multiple categories. 我是Meteor的新手,我正在开发一个可收集多个类别的表单条目的应用程序。 Form is custom built: 表单是定制构建的:

/*------------------- Template.html ----------------------------*/
<form class="word_of_day">
    <div class="page 1 view">
       <h1>Word of the day</h1>
       <p>Enter the word and fill out the fields as you go.</p>
       <input type="text" name="word" placeholder="Word of the day" />
    </div>
    <div class="page 2">
        {{> day_two}}
    </div>
    <div class="page 3">
        {{> day_three}}
    </div>
    <div class="page 4">
        {{> day_four}}
    </div>
    <div class="page 5">
        {{> day_five}}
        <div class="error"></div>
        <div class="pull-down">
           <span>Would you like to send this to yourself? (not required)</span>
           <input type="text" name="user_email" placeholder="Your Email" />
        </div>
    <button type="submit">Submit</button>
    </div>                  
</form>


/*---------------------- app.js ---------------------------------------*/
Template.form.events({
"submit .word_of_day":function(event){
  event.preventDefault();
});

Currently I have the form pushing the data into the Collections I have created but I can't figure out how to redirect the form after submission. 目前,我有将数据推送到我创建的集合中的表单,但是我不知道提交后如何重定向表单。 I have flow-router set up on the app, not sure if that helps. 我在应用程序上设置了流路由器,不确定是否有帮助。 I appreciate any help and guidance! 感谢您的帮助和指导!

In your events 在您的活动中

"submit .word_of_day":function(event){
  event.preventDefault();
  Meteor.call('updateYourData', $(event.target).serializeArray(), function(err, res){
      if (!err) {
          FlowRouter.go('path/to/some-where');
      }

  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM