How do I only allow one form entry per day?

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:

  1. In the form they are submitting add a date field, you can set this to be hidden. This will store the date in the Data Source.
  2. Use a form hook to check if they have already submitted it today and reject the promise from submitting the form again.

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

1 Like

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.