Limit number of form submissions by user with two value?

This code allow to limit the form submissions to users.
In this example I have a input box:
name=user_id
$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']}";
$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

What I need is:
First, in the above code I need 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.
Second,
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 it's called "paralelo_box" and has this values:
A
B
C
I need to do is, if  "A" value is selected, the number of form submissions per user change, the same for "B" and "C".
In this case:
A= 10 times
B= 9 Times
C= 11 Times
And Finally:
I would like to disable the submit button if the number of form submissions reaches the limit. The name of my submit button is "finalizar".
Thanks
LVL 1
plus_ecAsked:
Who is Participating?
 
plus_ecConnect With a Mentor Author Commented:
Hi, sorry for accept my own comment as solution, but any expert comment was useful to resolved my question.
Much time has passed since the beginning of my question, and this project I have to file for the day 28/02/2011.
Having no more options, I was trying to find the answer to my way with a cool head, and it succeeds.
I recently finish my proyect.
0
 
Ray PaseurCommented:
This is a strange-sounding application design.  Can you give us more of a plain-language description of the problem you are trying to solve?
0
 
plus_ecConnect With a Mentor Author Commented:
Ok, thanks for reply and sorry for my writing, I speak Spanish.
The question is that I need to place limits on sending form to the users, that I have it, is in the code above, the problem is that not all users have the same number of limitations:
For example.
If the user selects from the selectbox the option "A" limit will be 10, etc, etc.
In this case:
A = 10
B = 9
C = 11
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ray PaseurCommented:
Your English is much better than my Spanish!  I am just trying to understand the overall application design.  I have never seen such a thing and I have been around computer science for a while.  It makes me think that there is a design pattern that might be better than asking clients to choose a letter, then translating that letter into a number, etc.
0
 
plus_ecAuthor Commented:
yes, you are right, but which pattern you do you recommend?
0
 
plus_ecAuthor Commented:
What structure must be the most adecuate for designing what I asked before, as I was told my code is not the most optimal? and I need some code for guidance.
The overall idea is:
The user only access to the form with a simple password, after that, users must to choose a letter, and this letter is the key, depending on which letter the user has selected to place limitation of form submissions on each letter.
thanks.
0
 
Ray PaseurCommented:
What is the importance of asking the user to choose a letter?  Does the user know what meaning the letter conveys?
0
 
plus_ecConnect With a Mentor Author Commented:
This is the idea:
Is a simple evaluation system for teachers, is only a beta form, so, the student must to select your number of classroom, these are "A","B" and "C". Each student must to fill an approximated of 10 form, but not all, for example, students of classroom "A" should to fill 10 forms, classroom "B" 9 forms, and classroom "C" must to fill 11 forms. This is the reason why is important of asking user to choose a letter.
So, for me, is more easy limit the number of form submissions with a simple choice of the letter.
Please, if exist more question about this, just ask, I appreciate your help.

And this is my question:

I have a select box that is populated by javascript code, this select box it's called "paralelo_box" and has this values:
A
B
C

I need to do is, if  "A" value is selected, the number of form submissions per user change, the same for "B" and "C".
In this case:
A= 10 times
B= 9 Times
C= 11 Times


And this is my actual code:

$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']}";
$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!!!";// message if susbmissions reach limit

Open in new window

0
 
plus_ecAuthor Commented:
Any help please!! I'm stuck
0
 
Ray PaseurCommented:
Sorry, I am just not understanding the way you want to design the application.  This appears to use Joomla, right?  If so, ask a moderator to add it to the Joomla Zone.
0
 
plus_ecConnect With a Mentor Author Commented:
Hi,
I solved my question..
Here is what I was needing.
$username = $_POST['paralelo_box'];
	if ($username == "A") {
		if ($res >= 10 && $form->submitter >= 0 ) {
		$form->page = 2;
		$form->error = "here is the error message!!!";
		}
}

Open in new window


The same code is for each letter:
B= 9 Times
C= 11 Times
After $username, I change the value with a new one.
In this case, in the sentence "if" I change the value with a new one after "$res >=".
This works for me.

Thanks to all,
But by myself I have resolved the problem, so, I can't give Points, sorry.
0
 
plus_ecAuthor Commented:
Hi, sorry for accept my own comment as solution, but any expert comment was useful to resolved my question.
Much time has passed since the beginning of my question, and this project I have to file for the day 28/02/2011.
Having no more options, I was trying to find the answer to my way with a cool head, and it succeeds.
I recently finish my proyect.
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.