Creating One Time Submission Forms (Perfect for voting forms)

Do you want to create a voting form or a form that each of your users can submit only once? If so keep reading =), in this tutorial i am going to show you how to do exactly this.


In order to create this type of form you will need two things:

This extension will check that the current logged in user hasn’t submitted the form before so it is important to be sure that the user is logged in before doing the submission.


Getting Started

Once you have a new extension (which again, you can create like this ).  Validating that the form is not submitted more that once can be done with a few lines of code,  we only need to do this:

1.- Creating a hook that will be fired before the form is saved:

2.- Verifying that the form that is being submitted is the one that we want to modify, otherwise just let it go.

3.- Creating a query (using the smart forms query api) that checks if the current user has submitted this form before

4.- Make the plugin stop saving the form and send an error message if the current user has already submitted it.

And that’s it! At the end our extension should look like this :


And this is the end result:

In case you want to download the extension that i just did, here it is: smart-forms-one-time-submission

Did you like this tutorial? do you have any question? If so please let me know =)

Post a Comment

Your email is kept private. Required fields are marked *