Forums

Record User Name / Limit Submissions?

MNRachel 07 Dec, 2009
Hello!

I am wondering how the Submissions Limit in the General - Other Form Settings works? If you set that to limit one submission per day, for example, what does it use? Is it based on IP Address or something else?

I am wondering if I can record the Community Builder user name on the form submission and from there, if I can limit submissions based on the logged in user?

Without knowing what the standard submissions limiting is using, I'm not sure if I'm close or far off from accomplishing this🙂

Thanks for any guidance you can give me!

-Rachel
MNRachel 07 Dec, 2009
Quick update - I just figured out how to attach the user_id to the submission using the CB Registration plugin.

So just looking for clarification on the Submissions Limit standard settings and if it's not based on the user_id, if there would be a way to do that?

-Rachel
GreyHead 07 Dec, 2009
Hi Rachel,

I don't know what the Submissions Limit code does, I've never used it. I'll have a look in the code later and see if I can work it out.

Bob
MNRachel 07 Dec, 2009
I couldn't find documentation referencing the Submissions Limit but just noticed the info that is displayed when you hover over it - it states that it uses "user session". So I am guessing every time a visitor leaves and comes back to the site, it's a new session?

Which leaves me wondering if there is another way to limit one submission per registered user, now that I have captured the user_id?
GreyHead 07 Dec, 2009
Hi Rachel,

Your correct, the information is stored in the session so won't be maintained beyond the current session (the default is 15 minutes I think).

If you want to limit the submission to 1 per user, then (a) make sure you have the user_id stored in the results table (if you used Create Table then ChronoForms does this by default in the cf_user_id column); and (b) at the beginning of the Form HTML check the table for the current user id and only show the form if it isn't found.

Bob
MNRachel 07 Dec, 2009
Thanks for the quick responses!

I have created a table and verified that the user_id is correctly being stored in the table.

However, I don't know how to create coding.. any chance that you could guide me? Browsing through the tabs in the form, is this something that would go in the "validation" tab? (I see a sort of if/then example at the bottom). Or somewhere within the "form code" tab?
GreyHead 08 Dec, 2009
Hi Rachel,

The code goes in the beginning of the Form HTML and will be something like this:
<?php
if ( !$mainframe->isSite() ) return;
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
if ( !$user->id ) {
  echo "You have to be logged in to complete this form";
  return;
}
$query = "
  SELECT COUNT(*) 
    FROM `#_your_table_name`
    WHERE `cf_user_id` = ".$user->id." ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
  echo "You've already completed this form";
  return;
}
?>
// form html continues here
NB Not tested and will need de-bugging!!

Bob
MNRachel 09 Dec, 2009
Thank you, thank you, thank you!

This is working perfectly!

It runs the script when the page loads so the user needs to log in first but this is exactly what I was looking for. I hope it helps others out too🙂
This topic is locked and no more replies can be posted.