Limit form submissions

dbedlow 21 Jun, 2011
Can anybody tell me how to limit the submission of a form to one per user, or failing that, one per week?

Many thanks
GreyHead 21 Jun, 2011
Hi dbedlow,

Save the form data to a database, then use a Custom Code action in the OnLoad event to check the database and see if there has been a previous/recent submission. If there has then redirect the user with a message.

Bob
dbedlow 23 Jun, 2011
Thank you.

I'm afraid that my coding skills are roughly zero. Are you able to suggest some sample code I could use?
GreyHead 01 Jul, 2011
Hi dbedlow,

Sorry, there isn't a quick answer to this. It's not difficult - but it's not a five minute job either :-(

Basically if you've saved the form data using a ChronoForms created table then ther will be columns for the user ID and the record time. You need to add a MySQL query to check what else this user has submitted. I'd probably do that with a chunk of code in the beginning of the form HTML.
<?php
$user = \JFactory::getUser();
$db = \JFactory::getDBO();
$query = "
  SELECT COUNT(*)
    FROM `#__some_table`
    WHERE `cf_uid` = '{$user->id}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
  echo "You've already submitted this form";
} else {
?>
// Form HTML goes here
<?php
}
?>


Bob
dbedlow 07 Jul, 2011
Thank you. I'll let you know how I get on!
dbedlow 07 Jul, 2011
Hi,

I'm afraid this doesn't seem to work.

I'm wondering whether this is because the code supplied seems to check the cf_uid field, the value of which changes each time the form is posted.

Should it not check the cf_user_id field, which seems to remain constant? If so, which parts of the code need to be amended in order for this to work?

Many thanks
GreyHead 08 Jul, 2011
Hi dbedlow,

You're right, cf_uid was a bad choice. I think I intended cf_user_id; or maybe I was thinking of a new column with a unique user identifier. That said, the idea should still work OK.

Bob
This topic is locked and no more replies can be posted.