I have a system written in meteor where when someone submits a form it currently just shows a thankyou message in a modal. My client wants to be able to allow for multiple different thank you pages based on a thank you URL field on a clients record.
I am using iron router. I have successfully setup a server side route but I'm unable to even call that.
What I would like is to on form submission update the database then pull the clients thankyou URL and redirect the user to that. Sorry for not code to tweak but I'm just looking for the best way to handle it.
UPDATE:
Client Side
Meteor.call(
"addSendLeads",
{
bookingType: bookingType,
ad_platfrom: ad_platform,
senderID: email,
facebookPageID: fbPageID,
first_name: first_name,
last_name: last_name,
event_name: event_name,
startDate: startDate,
email: email,
phone: phone,
comments: comments,
},
(err) => {
if (err) {
console.log(err);
swal(
"Error",
"Sorry, there was an error. Please try again later."
);
} else {
target.firstName.value = "";
target.lastName.value = "";
target.email.value = "";
target.phone.value = "";
target.comments.value = "";
Router.go("/thankyou/" + url);
}
}
);
The Route in server/routes.js
Router.route("/thankyou/:url", { where: "server" }).get(function () {
this.response.writeHead(302, {
Location: url,
});
this.response.end();
});
Hope this helps to clarify...
Your submit form method should return your user custom URL, unless you pull that in the initial stage when you open the form.
With a method, you have a callback (pre Node16) or a .then(result => do_something_with_it). Async methods are already usable in Meteor 2.10.
Your call back or your async effect can call your routing:
Meteor.callAsync('submitForm', form) // or Meteor.call('name', {object data}, (err, res) => do_something_with_res)
.then(url => Router.go(url)
.catch(methodErrors => console.log(methodErros))