0

Possible to submit only one submission per email address?

I am trying to make the form gives an error if someone already has submitted and try submit again.

Thank you

1 Answer 1

0

If your users are filling in the form while logged in, you could look for Freeform entries authored by the currently logged in user and display the form only when no previous entries were found:

{exp:freeform:entries form_id="1" author_id="1"}
    {if freeform:no_results}
        {exp:freeform:form /* your other parameters */}
            // Your form...
        {/exp:freeform:form}
    {/if}

    {if freeform:count == 1}
        <p>You already submitted the form.</p>
    {/if}
{/exp:freeform:entries}

(Note: You will need to adjust form_id and author_id values based on your setup. IDs of "1" above are just an example)


Unfortunately, for logged out users, the above won't work since there is no id for logged out users. In the case of logged out users, although a user could submit an email address in a Freeform field. The next time the form is filled out with the same email address, there is no way to stop the user from entering the same email address again. The validation would have to occur after submitting the form a second time.

You could build an extension using some of the available hooks for Freeform: http://www.solspace.com/docs/freeform/extension_hooks/

Alternatively, although you can't prevent entering the same email address in a field, you could give the impression that submitting the same email address again is not possible. Here's an example of what could be done. Assuming your have a Freeform field called email:

  1. In {exp:freeform:form}, use return="template_group/template/%%entry_id%%" (provide your own template_group and template name, eg. form/thank_you
  2. In your template_group/template template, retrieve the submitted form data using {exp:freeform:entries entry_id="{segment_3}"} (segment_3 will be the latest Freeform entry_id).
  3. Pass the retrieved email in an embed which will check for pre-existing entries with the same email address:

template_group/template:

{exp:freeform:form entry_id="{segment_3}"}  
     {embed="check/email" email_field="{freeform:field:email}"}  
{/exp:freeform:form}

The embed:

{exp:freeform:entries search:email="{embed:email_field}"}
    {if freeform:no_results}Thank you for submitting{/if}
    {if count == 1}You already submitted the form with this email address{/if}
{/exp:freeform:entries}

Of course, within Freeform you will still see 2+ submissions with the same email (and even be notified more than once if you have email notifications set up), but the front-end user will see the "You already submitted the form with this email address" message the second time the form is submitted with the same email address. This is the illusion of a duplicate I mentioned earlier.

In the end, the better option would be creating an extension using the hooks.


UPDATE: There is an additional solution, using prevent_duplicate_on="". See: http://www.solspace.com/docs/freeform/form/#prevent_duplicate_on

This will allow you to detect duplicates based on email address (used with an email field). Perhaps the best approach.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.