0

I am trying to send an unique code when user submit their form.

Each unique code should send only once in order with each submission.

Any help would be appreciated.

1 Answer 1

0

The answer is similar to that given here: Solspace Freeform 4+ submission per email address

In summary:

  • Create an add-on that uses Freeform hooks to check for Freeform entries matching the token upon form submission
  • Give the illusion of a duplicate submission. It doesn't prevent submitting or saving the form again with the same token, but the front-end user would see a message upon duplication.

Additional solutions

If you're comfortable with AJAX and javascript/jQuery, you could have a field which, upon typing the token in it, calls a template in the background which contains {exp:freeform:entries}. This tag would check if any previous Freeform entries contain the same token (using the search:MY_FIELD="" parameter). If an entry is found, prevent the user from submitting the form through javascript (eg. blocking submission).

If you're not comfortable with AJAX or javascript/jQuery, you could do something similar, but with a simple HTML form which asks for the token code before the main Freeform form. Eg.

<form method="post" action="{path='template_group/template'}">
    <label for="token">Your token code:</label>
    <input id="token" name="token" placeholder="Eg. 123ABC" />
    <input type="submit" />
</form>

Then, after submitting the form and moving to template_group/template, using a plugin such as Mo'Variables, retrieve the token (it's a POST variable) and pass it in {exp:freeform:entries} to check for previous Freeform entries containing the same token code. Display the form if there are no previous Freeform entries, or display a message if a previous token is found:

{exp:freeform:entries search:token="{post:token}"}
    {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: The above uses Mo'Variables, but you could do this with PHP instead as well. Turn on PHP in EE (Input mode), and use <?php echo ee()->input->post('token', TRUE); ?> instead of the above {post:token}.

Your Answer

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

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