Solved

Limit number of form submissions by user with two value?

Posted on 2011-02-18
12
916 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHPStorm debugging issues 1 25
Checking if varaible is empty 6 32
Not seen Link button 5 19
How to count in a table in php 22 19
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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)

863 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

20 Experts available now in Live!

Get 1:1 Help Now