Solved

Limit number of form submissions by user with two value?

Posted on 2011-02-18
12
914 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:plus_ec
  • 8
  • 4
12 Comments
 
LVL 108

Expert Comment

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

Assisted Solution

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

Expert Comment

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

Author Comment

by:plus_ec
ID: 34926652
yes, you are right, but which pattern you do you recommend?
0
 
LVL 1

Author Comment

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

Expert Comment

by:Ray Paseur
ID: 34930018
What is the importance of asking the user to choose a letter?  Does the user know what meaning the letter conveys?
0
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

 
LVL 1

Assisted Solution

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

Author Comment

by:plus_ec
ID: 34935445
Any help please!! I'm stuck
0
 
LVL 108

Expert Comment

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

Assisted Solution

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

Accepted Solution

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

Author Closing Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

746 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

13 Experts available now in Live!

Get 1:1 Help Now