Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • The Fuel Agency 4 posts 73 karma points
    Dec 18, 2018 @ 00:49
    The Fuel Agency
    0

    Limiting the number of successful Formulate submissions

    Hello

    We were wondering if there was a way to limit the number of submissions a Formulate form could have before disabling. I have been delving into the code a bit and see that when the Formulate submission gets sent to the database, you can retrieve it on the backoffice, this uses AngularJS.

    However, I do not know if we can or how I might be able to utilize this previously written code to collect the number of submissions. Also, I am a little unclear how to extend Formulate by creating a 'form submission handler', as your Guided Tour as well as your Formulate Extensibility pages do not go into any practical code details in how to do this.

    Thanks for your time, and any pointers to capturing the number of successful form submissions and how to disable the form programmatically when the maximum number of submissions is reached would be of great value.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Dec 18, 2018 @ 17:37
    Nicholas Westby
    0

    We were wondering if there was a way to limit the number of submissions a Formulate form could have before disabling.

    Not super sure why you'd want to do this, but two options come to mind:

    • Submit a pull request so that the Submitting event (see here) allows for a form submission to be cancelled (e.g., by adding a boolean to the FormSubmissionContext). Then in your app, you can subscribe to that event and use whatever logic you like to cancel the submission.
    • Handle the logic for displaying (or not displaying) the form on your side. If too many submissions have been received for that form (using whatever logic you like to indicate "too many" submissions), then no longer display the form. You can query the table Formulate uses to store submissions (IIRC, it's called FormulateSubmission), supposing you're using the Store Data handler. Alternatively, you can create your own handler that has the singular purpose of counting form submissions using whatever method you like (e.g., storing the count to a database table).

    I am a little unclear how to extend Formulate by creating a 'form submission handler'

    Here is the short version:

    If you manage to get something working, would really appreciate it if you could write something up to add to the documentation: https://github.com/rhythmagency/formulate/tree/gh-pages/articles

    If you send me a pull request for a markdown file in that folder, it'll show up on the website, such as with this example: http://www.formulate.rocks/articles/custom-field-types

  • Anthony Edge 26 posts 80 karma points
    Dec 18, 2018 @ 22:45
    Anthony Edge
    0

    Limiting form submissions is actually a pretty common requirement:

    • Concert ticket giveaway: first 5 five responses win double passes
    • Community movie night reservations: only 100 double passes available
    • Pre-order your box of avocados: 50 available, arriving 12th Jan 2019
    • LAPD recruitment drive: 5000 applications will be collected for our upcoming officer role training courses

    :)

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Dec 18, 2018 @ 23:10
    Nicholas Westby
    0

    Thanks for those examples. I have never had to do that myself, but it makes sense now that you mention it.

  • Anthony Edge 26 posts 80 karma points
    Dec 18, 2018 @ 23:24
    Anthony Edge
    1

    In many cases, the trickle of form submissions means a form can be manually closed off and the few extra posts can be managed personally.

    But in cases where a wave of submissions are expected in a short period of time (ie, LAPD applications might reach 5000 submissions in 10 minutes) you really want to restrict the form from displaying to new visitors and manage people who already have the form open when they hit "submit". After the limit is reached it would be nice to show them an on-screen message of some kind (ie, "Sorry, the 5000 applications limit has been reached. Please try again next time").

    A few minutes spent counting and checking totals could result in thousands of unwanted additional submissions appearing before you shut it down manually and lots of unhappy people.

  • The Fuel Agency 4 posts 73 karma points
    Jan 11, 2019 @ 04:45
    The Fuel Agency
    0

    Looking at your Submissions.cs file, you mention that the FormSubmissionContext has a boolean to prevent form submission, but looking here at the anonymous class you create, and the subsequent Submit method, there seems to be no way to halt the submission using this context.

    I understand the concept, but without some way of checking that a flag is changed (and having a flag to change) before the form is submitted, this will not prevent the form from submitting.

    Thanks for any time, if you wish I can add a small bit of code change for your vetting.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 11, 2019 @ 17:36
    Nicholas Westby
    0

    Looking at your Submissions.cs file, you mention that the FormSubmissionContext has a boolean to prevent form submission

    Nope, I said that you can submit a pull request to create that functionality. It doesn't exist yet. Here is what I said for your reference:

    Submit a pull request so that the Submitting event (see here) allows for a form submission to be cancelled (e.g., by adding a boolean to the FormSubmissionContext). Then in your app, you can subscribe to that event and use whatever logic you like to cancel the submission.

    If you would like to modify the core of Formulate, please submit an issue here explaining your plan: https://github.com/rhythmagency/formulate/issues

    And then submit a pull request based off of the develop branch.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 21, 2019 @ 19:03
    Nicholas Westby
    0

    For anybody following this, The Fuel Agency submitted a pull request that has been merged in and released with the latest version of Formulate (2.2.0).

    Here is the pull request for reference: https://github.com/rhythmagency/formulate/pull/131/files

    You can now hook into the form submitting event and prevent submissions (e.g., if the maximum number of submissions has been reached).

Please Sign in or register to post replies

Write your reply to:

Draft