PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

User must be logged in and limit one submission per user

  1. blackburn
    Member

    Hello

    I'm trying to create a quiz entry type form where the user must be logged in to submit and they can only submit once.

    Basically I've got a number of multiple choice questions (that are marked as *required* so the user can't accidentally submit before completing them)

    I've also created a hidden field titled Email that automatically inserts the users email address INSERT VARIABLE: {user:user_email} if they are logged in. I've also made this a required field so technically they shouldn't be able to submit without being logged in (otherwise it would be blank). I've also checked the NO DUPLICATES box so that the user can't submit twice.

    I've done the same for USER LOGIN.

    All this sounds like it should work just fine but whether I'm logged in or logged out, I can submit as many times as I want. Checking the submissions, it is recording my email address and USER LOGIN but it isn't stopping submissions when I'm not logged in (both fields are blank) and it also isn't stopping multiple submissions from the same user.

    Thoughts?

    Posted 13 years ago on Wednesday July 27, 2011 | Permalink
  2. blackburn
    Member

    Anyone have any thoughts on this one?

    I'm ultimately looking for a way to require a user to be logged in in order to submit (and limiting submissions to one-per-user).

    Sounds feasible as I described above but just isn't working as expected...

    Thanks for your help :)

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  3. Why not place the form on a page that requires a login first? Sort of like members only content: it's visible only once you're logged in. That would at least prevent them from submitting when NOT logged in. I think you could use the is_user_logged_in function in either a small plugin, shortcode function or page template.

    That would take care of the first part (they will only see the form if they are logged in.)

    Regarding how you are getting the email of a logged in user: you posted {user:user_email} - how does that work to get the email address of the logged in user? Where did you enter that code and why (how) does it work? Is the coming from a field in your form or somehow from the usermeta table?

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  4. blackburn
    Member

    Hi Chris

    Thanks for your reply - that's right - it's a relatively simple fix to take care of the 'must be logged in part' (though technically my understanding of how the form works *should* have been able to take care of that)

    As for the second part, I am using ADVANCED FIELDS > EMAIL and then going into the ADVANCED TAB of that element and under DEFAULT VALUE > INSERT VARIABLE > USER EMAIL {user:user_email}

    If this is a required field and also a hidden field, this *should* auto-populate with the user's email address when logged in.

    If I check NO DUPLICATES, it should also limit the user from submitting more than once.

    I may not be understanding this correctly, but this doesn't appear to be working for me. It is allowing me to submit as many times as I want.

    When I am logged in, it IS recording my email address (I did the same with a field to capture USER LOGON) but it is still allowing for duplicates.

    Thanks again for your help.

    Cheers!
    Dale

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  5. I don't quite understand your setup.

    For the Advanced Fields > Email, that is a visible field you are requiring your visitor to fill out? Or, do you mean that's marked "admin only"? A hidden field is a completely different type of field. AFAIK, you can't make an email field "hidden", unless by hidden you mean "admin only". A link to your form will help clarify this for me.

    There is a conflict when making an admin only field "required". How would the visitor know if an admin only field was present in order to be able to fill it out as required? And if the value were not present, should the validation say "admin only email field is blank. But it's hidden so I can't let you fill it out since you don't know it's here." So, I don't think this works well. I'm trying to find previous discussions about that.

    Thanks for the clarification. We'll get it sorted.

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  6. I just set up a quick form with Advanced > Email as required, admin only, no duplicates and default value of {user:user_email}. So, it's not shown on the front end, it is populating my email address when I am logged in, and it allowed me to submit multiple times, ignoring the "no duplicates" setting.

    Maybe the rule "no duplicates" does not work in conjunction with the default value, or the default value is populated after the validation is done? I'm sure I just don't understand how it works yet.

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  7. I changed my form to allow me to type in my email address, so I used the same email address, and I could not submit since it was a duplicate. So it appears that the {user:user_email} is set after the validation (maybe?)

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  8. blackburn
    Member

    I'm sorry for the confusion Chris but yes, you got it right, I do have the form set to ADMIN ONLY.

    Assuming that I require the user to be logged in before they can see the form, it shouldn't be an issue if the email field is visible to ADMIN ONLY and populated with a default value of {user:user_email} because there will always be a proper email associated.

    So it appears that the {user:user_email} is set after the validation (maybe?)

    I've made the field visible (unchecked ADMIN ONLY) and then went to the form and my email was already auto-entered - this leads me to believe that this field is being set before the validation, but maybe not...

    Hmmm... I'm wondering if there are any other ways around this to achieve a 'contest entry' type use that limits entries from users.

    If I leave it open so that users can enter their own email address, they can technically enter multiple times with different email addresses. I want to restrict it to email addresses that are "club members"...

    Instead of using the DEFAULT VALUE field, is it possible to achieve the desired outcome with the ALLOW THE FIELD TO BE POPULATED DYNAMICALLY option?

    Thanks Chris.

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  9. It sounds like you may want to do some custom validation of some sort using the gform_validation hook. You would need to write custom validation to check to see if the user has already entered by querying entry data directly, and then show a validation error message if they have. You could either use the gform_validation hook to do this when the form is submitted or you could write custom PHP to do this before the form is displayed. Either way it requires custom code to do this properly. How comfortable are you writing custom PHP or using hooks/filters?

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  10. blackburn
    Member

    On a scale of 1 to 10, about -3.

    haha

    I can implement anything you throw my way... as far as having the knowledge to do it on my own... I'm all for a little hand-holding. haha

    Posted 13 years ago on Wednesday August 3, 2011 | Permalink
  11. blackburn
    Member

    Is there a codex or documentation that I can reference with respect to the gform_validation hook? This might appear to be the easiest solution to the above issue.

    Posted 13 years ago on Monday August 8, 2011 | Permalink
  12. There is a tutorial on how to use the gform_validation hook to write custom validation here:

    http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_valiation%22_Hook

    Posted 13 years ago on Monday August 8, 2011 | Permalink
  13. I know this is an old thread. Can Gravity Forms now do what the OP was asking?

    I'm looking for something similar.

    1) require that users be logged in (can do this)
    2) auto enter their username or email address (can do this)
    3) no duplicates (not sure if this can be done)

    Posted 11 years ago on Tuesday July 9, 2013 | Permalink
  14. David Peralty

    You can test no duplicates on any single field in a form. There is a check box on each field that says No Duplicates.

    Posted 11 years ago on Tuesday July 9, 2013 | Permalink

This topic has been resolved and has been closed to new replies.