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.
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communityThe answer is similar to that given here: Solspace Freeform 4+ submission per email address
In summary:
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}
.