Limit number of form submissions by user?

I would like to know if exists a possibility to limit the number of form submissions by user.
This is the idea:
One user can submit the form just 10 times, and no matter how many form submissions made per day the user have, only interested the limit of form submissions per user_id the user has.
The users need to be registered to access the form, this I have it. I taken the user_id from the table "users", and this is stored in the new table to allow user submit form only 10 times, but, I can't do the last part.
I guess that this can be implement with some javascript code, some kind of counter that store the number of form submissions and if it reach the limit this one disable the submit button. I do not know.
Or maybe store a new auto-incremental value into table, and if user reach the limit of form submission the javascript disable the submit button.

This is an example of a simple form:
<table border="1" align="center" cellpadding="0" cellspacing="0">
  <col width="24" />
  <col width="508" />
  <col width="31" />
  <col width="34" />
  <tr>
    <td align="right" width="24">7</td>
    <td width="508"><div align="center">CONDUCTA </div></td>
    <td width="31"><div align="center">SI</div></td>
    <td width="34"><div align="center">NO</div></td>
  </tr>
  <tr>
    <td height="34">7.1</td>
    <td width="508">El profesor    incurre en la práctica de sobornos para mejorar su calificación.</td>
    <td><div align="center">
      <input type="radio" name="7_1" value="1" />
    </div></td>
    <td><div align="center">
      <input type="radio" name="7_1" value="2" />
    </div></td>
  </tr>
  <tr>
    <td height="34">7.2</td>
    <td width="508">Ha    sido víctima de algún tipo de acoso.</td>
    <td><div align="center">
      <input type="radio" name="7_2" value="1" />
    </div></td>
    <td><div align="center">
      <input type="radio" name="7_2" value="2" />
    </div></td>
  </tr>
</table>

<div align="center">
  <input type="submit" value="Finalizar">
</div>

Open in new window


This will be implement on joomla, specifically on smartformer gold plugin, this allow to insert java, php and all msdn library.

Any help?
Thanks.
LVL 1
plus_ecAsked:
Who is Participating?
 
plus_ecConnect With a Mentor Author Commented:
I provide the code and it was only a small part that needed to be changed.
In the original question I just provide HTML code, and I was needing the php code to implement in my proyect. Seeing that anyone provide a code, I put my own code, and almost all part of my code was right, only a small part that needed to be changed.
I'm sorry but I have to present this project tomorrow, and I recently finished.
Thanks to all for your help.
0
 
PranjalShahCommented:
I think doing the auto increment is right way to go about this.

I would go one step further than just disabling the submit button, disable all the text boxes and also dont show any radio buttons just print the values of that. Also print the message  on the top that your maximum changes are done that way user will have an idea and he wont make any changes to the form.
0
 
Lukasz ChmielewskiCommented:
PranjalShah is right. Disabling the whole form would be the best thing to do - the user can press enter on any of the textboxes to submit the form. I would not show the form if the submissions field value = 10.
It would be incremented every time after user submits the form with a query
$q = "update mytable set submissions = submissions + 1 where user_id = $_POST[userid";]
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Ray PaseurCommented:
Are your users required to login to the site in order to submit information?  I think that is what you have described but it would be necessary to be clear about it.

Each time the user submits a form, you would add the submission to a table in your data base.  The table would also contain the user-id and a DATETIME field showing when they submitted the form.  In your script that prepares the form for them, you would just query this table with SELECT user_id FROM mytable WHERE (current User ID) LIMIT 10.  Then you can test mysql_num_rows() and if it is 10, you've hit the limit.  No more forms, no more submissions.  I like the idea of showing the grayed-out text boxes.  That is good UI.  You might also show the user a count of the number of allowable form submissions remaining.

With the DATETIME column, you could do something like allow X number of submissions per day.
0
 
plus_ecConnect With a Mentor Author Commented:
Thanks guys for reply,
This is an example of my php code that limit number of form submissions by day.
I need something like this but instead to form submissions by day, this will be form submissions per user.
In this example I have two input boxes:
name=user_id
name=day
The fist one is taken from other table where user_id is stored.
$form->data['day'] = floor(intval(date("U"))/60/60/24);
$form->data['user_id'] = &JFactory::getUser()->id;
$db_name =  $form->formXMLStruct['database']['name'];

$query = "select count(id) from $db_name where user_id={$form->data['user_id']} and day={$form->data['day']}";
$database = &JFactory::getDBO();
$database->setQuery($query);
$res = $database->loadResult();
if ($res == null) die($query);
echo $res;
if ($res >= 10 && $form->submitter >= 0 ) $form->error = "Error!!!";//Ok, here the error message if susbmissions reach limit

Open in new window

I need something like this but instead to form submissions by day, this will be form submissions per user.
I do not know how to implement with your examples. I'm stuck.
I like the idea of showing the grayed-out-text boxes and the remaining counter.
0
 
PranjalShahConnect With a Mentor Commented:
Increment the table counter after each submission per user and then if you just want to have per user dont include the condition for day in the query.

$query = "select count(id) from $db_name where user_id={$form->data['user_id']}";


0
 
plus_ecAuthor Commented:
Works fine, but the number of form submissions is displayed on top of form, what I need is to this value is displayed in a text box called "total_submit", and the the error message, this is displayed below the number of form submissions, what I need is to be displayed in a common popup alert message.

And what happens if I have another value that is necessary to know how many form submissions the user should do.
For example:
I have a select box that is populated by javascript code, this select box has this values and it's called "paralelo_box"
A
B
C
What I need to do is, if  "A" value is selected, the number of form submissions per user change.
In this case:
A= 10 times
B= 9 Times
C= 11 Times
0
 
Ray PaseurCommented:
That sounds like a completely different question.  You might want to open a new question and post the code you are using now.  My only caution would be that you need to be very careful about relying on JavaScript to control any behaviors that modify the data model.  JS is client-side programming and so it can be bypassed, tampered with, etc.  By definition any data that is "validated" with JavaScript is tainted and must be filtered on the server before it is used in any programming.
0
 
plus_ecAuthor Commented:
Ray paseur:
Thanks,
Yes, you are right, but I need to know if exists a possibility to put the error message and the counter message in a text box for each one? I do not know how to translate each one in a text box.
And about your idea of "showing the grayed-out text boxes. You might also show the user a count of the number of allowable form submissions remaining.", how I can implement this in my code?
About my other question I going to post a new question with my actual code.
0
 
PranjalShahCommented:
As Ray said, open a new question with your code and we can see what you are doing.
0
 
plus_ecAuthor Commented:
I opened a new question with my code, please if someone help me, I really appreciate it...
Limit number of form submissions by user with two value?
0
 
PranjalShahCommented:
Hi Pluc_EC

You dont need to close this question. Just award the points and keep the question, that way someone else with the same issue can look up this thread for assistance.
0
 
plus_ecAuthor Commented:
Hi pranjalShah.
Yes, you are right, but I do not know how to do that..
0
 
PranjalShahCommented:
I think if you dont award points to yourself and just award it to me, it should let you do that. I am not sure though...
0
 
plus_ecAuthor Commented:
Maybe, but as you can see in all my questions I deserve award points too..
Anyway, Thanks PranjalShah for your answer, you will get points too.
0
 
plus_ecAuthor Commented:
I provide the code and it was only a small part that needed to be changed.
In the original question I just provide HTML code, and I was needing the php code to implement in my proyect. Seeing that anyone provide a code, I put my own code, and almost all part of my code was right, only a small part that needed to be changed.
I'm sorry but I have to present this project tomorrow, and I recently finished.
Thanks to all for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.