Hi,
I want the user to enter their weight and other measurements only once per day. Once they hit that submit button, I don’t want them to be able to do it again until the next day.
How do I do this?
Thanks,
Vish
Hi,
I want the user to enter their weight and other measurements only once per day. Once they hit that submit button, I don’t want them to be able to do it again until the next day.
How do I do this?
Thanks,
Vish
Hi Vish,
You will need to use custom code to achieve this, which you can access using the Developer options > Javascript.
The general idea is the following:
Example JS:
Fliplet.Hooks.on("beforeFormSubmit", function (data) {
//change the DS id below to the data source where the entries are stored.
return Fliplet.DataSources.connect(123)
.then(function (connection) {
return connection.find({
where: {
Email: data.Email,
Date: moment().format("YYYY-MM-DD")
},
});
})
.then(function (records) {
if (records.length > 0) {
return Promise.reject("You have already submitted the form today");
}
});
});
Let me know if you need anything else.
Thanks,
Deb
This worked perfectly. Thank you!!
The findOne method can also be used to simplify the code a little more:
Fliplet.Hooks.on("beforeFormSubmit", function (data) {
return Fliplet.DataSources.connect(123)
.then(function (connection) {
return connection.findOne({
where: {
Email: data.Email,
Date: moment().format("YYYY-MM-DD")
},
});
})
.then(function (record) {
if (record) {
return Promise.reject("You have already submitted the form today");
}
});
});
This is also going to be faster because the app only has look up for whether one record exists for the given query, instead of looking for more.