Link to home
Start Free TrialLog in
Avatar of plus_ec
plus_ecFlag for Ecuador

asked on

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.
Avatar of PranjalShah
PranjalShah
Flag of United States of America image

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.
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";]
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.
SOLUTION
Avatar of plus_ec
plus_ec
Flag of Ecuador image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plus_ec

ASKER

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
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.
Avatar of plus_ec

ASKER

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.
As Ray said, open a new question with your code and we can see what you are doing.
Avatar of plus_ec

ASKER

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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of plus_ec

ASKER

Hi pranjalShah.
Yes, you are right, but I do not know how to do that..
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...
Avatar of plus_ec

ASKER

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.
Avatar of plus_ec

ASKER

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.