Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Limit number of form submissions by user with two value?

Posted on 2011-02-18
12
Medium Priority
?
928 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
[X]
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
  • 8
  • 4
12 Comments
 
LVL 111

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 111

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 111

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 111

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses

618 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