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

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

本文关键字:帮助 重定向 提交 构建 自定义 表单 流星      更新时间:2023-09-26

编辑:我确实在表单元素中添加了action="/results",但它没有做任何事情。我还在我的路线上设置了页面/results

Meteor 的新手,我正在开发一个收集多个类别表单条目的应用程序。表单是定制的:

/*------------------- 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();
});
目前,我

有表单将数据推送到我创建的集合中,但我无法弄清楚如何在提交后重定向表单。我在应用程序上设置了流路由器,不确定是否有帮助。我感谢任何帮助和指导!

在您的活动中

"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');
      }
  });
}