0

So we have site that allows logged in members to view job postings and send a form to apply to the job view Freeform. The issue we are looking at resolving is preventing duplicate submissions to the same job by a logged in member.

If we use "prevent_duplicates_on", then it will not allow the user to apply to other jobs since they all use the same form. Freeform would look in the system and find that this person (based on the members email) has already sent a submission. But, the system doesn't see that the member sent a submission to a different job.

Any way around this?

Thanks! Dan

1

You'll need to write an extension to perform this kind of check.

Use the freeform_module_validate_begin hook, and then do something like this:

Look up entries in the exp_freeform_entries table which match the author_id to ee()->session->userdata('member_id'), and whatever your form field is which holds the job being applied for (ID or name or whatever) to the matching value for that field in the database.

(Look at your database directly to figure out table and field names for this, it will save you time and headaches!)

If you find a match, add a new error to the$errors array, and return it. Otherwise, just return the $errors array as you received it.

  • So there is no way around this but to write an extension? Issue is that I've never written one. – DanH Jan 19 '15 at 22:11
  • AFAIK, no, no way around writing custom code here. The built-in duplicate prevention feature is per-form - it does not allow for denying duplicates only based additionally on the presence of specific form data (which is what you need). – Derek Hogue Jan 19 '15 at 22:48
  • Thanks Derek...I actually think your format makes the most sense in terms of being dynamic and reducing the overhead required for running additional queries. That said, I'm not familiar with Extensions and was able to find a different solution which I'm posting in this. Your help is greatly appreciate though and your thoughts on the solution are also welcome! :) – DanH Jan 20 '15 at 3:47
1

So after playing around with it and asking Solspace the solution seems to be as follows: you create a field in Freeform for the ID of the entry (in this case the job posting) that the person is responding to. You fill in this field by making it hidden to the user and automatically assigning the entry_id of the channel entry to the hidden field. Then you use the

{exp:freeform:entries form_name="my_form" author_id="{embed:member_id}" search:entry_id="{entry_id}"}

This will give you all items in the form that have the author_id (the person submitting the form) for a specific form. If it comes back as no results, you can display the form to the user. If it comes back with a result, you simply tell the user they have already responded to this posting.

As for the embed for author_id, there seems to be an issue using:

{logged_in_member_id}

inside of:

{exp:freeform:entries}

tag, so you create an embed which you call with something like:

{exp:channel:entries}
   <h3>{title}</h3>
   <p>{body}</p>
   {embed="path_to/template_with_freeform_entries" member_id="{logged_in_member_id}"}
{/exp:channel:entries}

If anyone sees any issues with this, please let me know...or if there are better ways to do this (without writing an extension which I've never done before).

Hope this helps someone.

Derek, any thoughts or comments on this approach? And again, thank you for your responses.

1

An alternative answer to the above method of embeds is also to use the Mo Variables add-on and make {logged_in_member_id} available for early parsing and then you don't have to use embeds.

So here is the final code that worked:

{exp:freeform:entries form_name="my_form" author_id="{logged_in_member_id}" search:form_entry_id="{entry_id}"}
    {if freeform:no_results}
        {exp:freeform:form form_name="job_application" admin_notify="{application_email_address}"}
            <input type="hidden" name="applicant_name" value="{logged_in_screen_name}"/>
            <input type="hidden" name="email" value="{logged_in_email}"/>
            <input type="hidden" name="form_entry_id" value="{entry_id}"/>
            <input type="hidden" name="post_title" value="{title}"/>
            {freeform:submit}
        {/exp:freeform:form}
    {/if}
    {if freeform:absolute_results >= 1}
        You have already submitted for this post.
    {/if}
{/exp:freeform:entries}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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