Can I restrict amount of form entries by users?

davestrand 02 Apr, 2009
Hi there, this might be an easy fix, or maybe not.

I'm a bit new to this. So far, I've been able to get a working form on my site using Chrono Forms, and also get a page up where users can browse the form entries on my website using Chrono Connections. I've actually purchased the license and am very happy with these forms and how it's all working out. Heck, I even have my Community Builder pulling username information from the database...

Here's the next step for me. I have searched the Forums but can't find any reference to this.

I would like to restrict each User on my site to a maximum of 5 form entries at any given time. If they delete one of their entries (which I have working) then they can make a new entry... but never any more than 5 entries in the database from any one user. Possible? Tricky? Lmk. Thanks!



-Dave
Chandler, AZ
davestrand 02 Apr, 2009
Let me clarify.. I'm not certain what the proper words are when it comes to forms.

When I say form entries, each entry would contain many fields of information... like state + description + email (for example). I would restrict each user to 5 submitted form entries, each of which contain many fields.

Thanks.
GreyHead 02 Apr, 2009
Hi Dave,

A bit tricky, at the beginning of the Form HTML you'll need to query the database and check how many entries they have and then show them an appropriate form - either an empty form if they have less than five or an update selection if they already have five.

Bob
davestrand 02 Apr, 2009
Ah.. sounds like the coding may be a little above me. I might have to consult with some of my smarter friends to get some custom code made then. Thanks for putting me on the right track, though.
GreyHead 02 Apr, 2009
Hi Dave,

Sounds good, the coding is only a few lines once you've clearly defined what you need to do - especially in the 'edit' case.

Bob
davestrand 03 Apr, 2009
Hah! I just spent a nice amount of time today in a feeble attempt to learn some basic SQL functions... I learned about Select, From, Select Count, and a bunch of other fun stuff, and I think I actually understood a little of it... Then I finally got the balls to try and fiddle with this problem of mine in the html coding section and I realized that the language I might have needed to learn appears to be PHP. I'm such a newb.

Anyone freelance code? My coding friend is swamped at work.

If so, more info...
So it appears that my table is called jos_chronoforms_submitform555 and the data column i need to count is cf_user_id, so that if the user that is logged in has posted 5 times he can't post anymore. Maybe even have a little text when they get to the form screen in red that says, you have reached your limit of 5 posts.

Anyhow, lmk how much this might cost if anyone's interested? P.M. is okay.
I might have more work after this one if my coding friend remains tied up.

Thanks,
-Dave

Chandler, Arizona
GreyHead 03 Apr, 2009
Hi Dave,

Try this
<?php
$db =& JFactory::getDBO();
$user =$ JFactory::getUser();
$query = "
  SELECT count(*) 
    FROM `#__chronoforms_submitform555`
    WHERE `cf_user_id` = $db->Quote($user->id) ; ";
$db->setQuery($query);
$count = $db->loadResult();
If ( $count >= 5 ) {
  // show edit list
} else {
  // show new entry form
}
?>

Bob
davestrand 03 Apr, 2009
Wow, thanks for hookin me up!

Didn't work yet, but it's probably something silly on my end. I tried pasting your code into various places, but it kept returning an error message like this when I would visit the page.


Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/.cara/hobathehut/hobjoblin.com/components/com_chronocontact/chronocontact.php on line 3


I pasted it above the existing page's code at the top in the following three locations, one at a time.

* I tried the code html view in Chrono Forms
* I tried the chronocontact.html.php
* I tried the chronocontact.php

All yielded the same results. Lmk what ya think, it's probably something silly on my end.

Many thanks,
-Dave
davestrand 03 Apr, 2009
Oh No! Why is the delete button so close to the edit button! Hah! There's no way to get my form back now, oh well.. no problem. Do over.
GreyHead 03 Apr, 2009
Hi Dave,

Sorry typo crept in
$user =& JFactory::getUser();
(not =$)

Bob
davestrand 04 Apr, 2009
Awesome! Got it working.. Thanks so much for all the help Bob.

Here's the final code we ended up using..

<?php
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $query = "
      SELECT count(*)
        FROM `#__chronoforms_submitform555`
        WHERE `cf_user_id` = $db->Quote($user->id) ; ";
    $db->setQuery($query);
    $count = $db->loadResult();
If ( $count >= 5 ) {
  Header("Location:http://www.RedirectedURLhere.com");
} 
//don't need an else here...greater than 5 is the only time we redirect.
?>
GreyHead 05 Apr, 2009
Hi Dave,

Well done.

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