Solved

Limit number of form submissions by user?

Posted on 2011-02-17
16
1,136 Views
Last Modified: 2012-08-13
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.
0
Comment
Question by:plus_ec
  • 8
  • 5
  • 2
  • +1
16 Comments
 
LVL 8

Expert Comment

by:PranjalShah
ID: 34919565
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34920092
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34921126
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
 
LVL 1

Assisted Solution

by:plus_ec
plus_ec earned 0 total points
ID: 34921390
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
 
LVL 8

Assisted Solution

by:PranjalShah
PranjalShah earned 500 total points
ID: 34921463
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
 
LVL 1

Author Comment

by:plus_ec
ID: 34923207
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 34925136
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
 
LVL 1

Author Comment

by:plus_ec
ID: 34926064
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 8

Expert Comment

by:PranjalShah
ID: 34928280
As Ray said, open a new question with your code and we can see what you are doing.
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34935453
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
 
LVL 1

Accepted Solution

by:
plus_ec earned 0 total points
ID: 34994221
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
 
LVL 8

Expert Comment

by:PranjalShah
ID: 35000100
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
 
LVL 1

Author Comment

by:plus_ec
ID: 35000251
Hi pranjalShah.
Yes, you are right, but I do not know how to do that..
0
 
LVL 8

Expert Comment

by:PranjalShah
ID: 35000273
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
 
LVL 1

Author Comment

by:plus_ec
ID: 35000329
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
 
LVL 1

Author Closing Comment

by:plus_ec
ID: 35034692
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now