Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Limit number of form submissions by user with two value?

Posted on 2011-02-18
12
921 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 109

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 109

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 109

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
 
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 109

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html fieldset fix its height and width 4 28
Obtaining data on ASP 8 28
Copying table data to one another 15 29
issue with DB import 1 17
This article discusses four methods for overlaying images in a container on a web page
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 …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

840 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