• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Setup form so each user can only submit once ?

Setup form so each user can only submit once ? 14 years 3 months ago #9162

I'm sorry if this is dumb question as I am new to RSForms (Pro).

Is it possible to setup a form so that each user can only make 1 submission ?

I want to use RSForms for a Survey so therefore everyone should only provide 1 set of answers.

Help Appreciated ..... :woohoo:
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 14 years 3 months ago #9165

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

In order to stop the same user from submitting the form more than once you will have to paste this script in the "Scripts called on form display" area:
$rsuser =&JFactory::getUser();
$myid = intval($rsuser->get('id'));
if ($myid > 0 && mysql_num_rows(mysql_query("SELECT `SubmissionId` FROM `jos_RSFORM_SUBMISSIONS` WHERE `UserId`='".$myid."' AND `FormId`='1' LIMIT 1")) > 0)
$formLayout = 'You have already completed this form.';

Note that in the script you will have to change the FormId value to the id of the form that you use.
Last Edit: 14 years 3 months ago by bogdanc.
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 14 years 3 weeks ago #9951

Is there a way to pull this off without needing to be a user? Say, by IP?

I have a simple survey form that is available to all guests, but only want them to fill it out once.
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 14 years 3 weeks ago #10001

  • patrick.jackson2
  • patrick.jackson2's Avatar
  • OFFLINE
  • Fresh Boarder
  • KPS - Joomla Consultant Melbourne Australia
  • Posts: 12
  • Thank you received: 6
andrew.norris wrote:
Is there a way to pull this off without needing to be a user? Say, by IP?

I have a simple survey form that is available to all guests, but only want them to fill it out once.

Have a similar issue at the moment with a form needing to be restricted for a competition for one entry per email address.

Will post code when I figure it out, unless you worked yours out already and care to share?
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 14 years 2 weeks ago #10047

  • bogdanc
  • bogdanc's Avatar
  • OFFLINE
  • Moderator
  • Posts: 669
  • Thank you received: 11
Hello,

If you wish to limit the user submission depending on the user's IP address then you can try placing a script similar to this one in the "Scripts called on form display" area:
$rsip =$_SERVER['REMOTE_ADDR'];
if (mysql_num_rows(mysql_query("SELECT `SubmissionId` FROM `jos_RSFORM_SUBMISSION_VALUES` WHERE `FieldValue`='".$rsip."' AND `FormId`='56' LIMIT 1")) > 0)
$formLayout = 'You have already completed this form.';

Also if you wish to prevent the same email address from submitting the form twice then you can try using a script similar to this one in the "Scripts called on form process" area:
$rsemail = $_POST['form']['email'];
$foundValid = false;
if (mysql_num_rows(mysql_query("SELECT `SubmissionId` FROM `jos_RSFORM_SUBMISSION_VALUES` WHERE `FieldValue`='".$rsemail."' AND `FormId`='56' LIMIT 1")) > 0)
$foundValid = true;
if($foundValid)
{
$invalid[]=RSresolveComponentName('email',$formId);
echo RSshowForm($formId, $_POST['form'], $invalid);
}

Note that in the script you will have to change the FormId value to the id of the form that you use and also the field "email" to the field which captures the user's email in your form.
Last Edit: 14 years 5 days ago by bogdanc.
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 13 years 9 months ago #10737

I'm trying to use the code that will prevent an email address from submitting a form multiple times.
 
$rsemail = $_POST['form']['email']; 
$foundValid = false; 
if (mysql_num_rows(mysql_query("SELECT `SubmissionId` FROM `jos_RSFORM_SUBMISSION_VALUES` WHERE `FieldValue`='".$rsemail."' AND `FormId`='4' LIMIT 1")) > 0) 
$foundValid = true; 
if($foundValid) 
{ 
$invalid[]=RSresolveComponentName('email',$formId); 
echo RSshowForm($formId, $_POST['form'], $invalid); 
}

I put the code in place and changed the FormId, but it's not working. I'm using RS Form Pro 1.2.0. And the Joomla 1.5.18.

Any suggestions?
Last Edit: 13 years 9 months ago by brian.woolard. Reason: code update
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 13 years 8 months ago #10879

  • shweew
  • shweew's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
brian.woolard wrote:
I'm trying to use the code that will prevent an email address from submitting a form multiple times.
 
$rsemail = $_POST['form']['email']; 
$foundValid = false; 
if (mysql_num_rows(mysql_query("SELECT `SubmissionId` FROM `jos_RSFORM_SUBMISSION_VALUES` WHERE `FieldValue`='".$rsemail."' AND `FormId`='4' LIMIT 1")) > 0) 
$foundValid = true; 
if($foundValid) 
{ 
$invalid[]=RSresolveComponentName('email',$formId); 
echo RSshowForm($formId, $_POST['form'], $invalid); 
}

I put the code in place and changed the FormId, but it's not working. I'm using RS Form Pro 1.2.0. And the Joomla 1.5.18.

Any suggestions?

It is strange, why the code does not work for me?
I too use RS Form Pro 1.2.0. And the Joomla 1.5.18. :(
Help to troubleshoot.
Last Edit: 13 years 8 months ago by shweew.
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 13 years 8 months ago #10897

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 713
  • Thank you received: 59
Hello,

Instead of using a custom script in order to validate a unique value please try going to components/com_rsform/controller, edit the validation.php file and add the following function after the already existing ones:
function unique($param, $extra=null)
{
if (!email($param,null))
return false;
 
$db = JFactory::getDBO();
$param = $db->getEscaped($param);
$db->setQuery("SELECT * FROM #__rsform_submission_values WHERE `FieldName`='Email' AND `FieldValue`='".$param."'");
$db->query();
$invalid = $db->getNumRows();
if ($invalid)
return false;
return true;
}

This will create a new validation rule for all your forms. In order to apply it you just have to edit your fields and select "unique" for the "Validation rule".
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 13 years 5 months ago #11806

  • ashley.barnard
  • ashley.barnard's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 2
I have just added this code to my site to prevent users from submitting the form more than once and i get the following error

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/xxxxxx/public_html/administrator/components/com_rsform/helpers/rsform.php(1043) : eval()'d code on line 3

Any help sorting this out will be usefull
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 13 years 4 months ago #11976

As ashley.barnard said, I am also getting the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home3/xxxx/public_html/xxxxx/administrator/components/com_rsform/helpers/rsform.php(1099) : eval()'d code on line 4

Please help
The administrator has disabled public write access.

Re:Setup form so each user can only submit once ? 13 years 2 months ago #12457

  • patrick.jackson2
  • patrick.jackson2's Avatar
  • OFFLINE
  • Fresh Boarder
  • KPS - Joomla Consultant Melbourne Australia
  • Posts: 12
  • Thank you received: 6
Restrict by IP address

An update to bogdanc's code that works with RSForms 1.3.0 and above.
// Determine the IP address for the user
$rsip =$_SERVER['REMOTE_ADDR'];
 
// Look up the IP address and see if it's already submitted for your form (suggestion: check your FormId number is correct)
if (mysql_num_rows(mysql_query("SELECT `SubmissionID` FROM `jos_rsform_submissions` WHERE `UserIP`='".$rsip."' AND `FormId`='3' LIMIT 1")) > 0)
 
// If the IP address already exists, display alternative content for the form layout (suggestion: copy your thank you message)
$formLayout = 'You have completed this form already.';

Note that you need to change the FormId value to your Form number, and modify the value of $formLayout to what you want to have displayed instead of the form. In the form I created, it was to gather information before displaying videos to a client. The videos were displayed on the thank you message for the form, so my $formLayout field is set to the HTML contents of the thank you message.

You'll also need to be careful of ' " ` in your code, as this can cause a range of errors from incorrectly displaying HTML, through to what may be the cause of ashley.barnard and mutwirik3's problem - if the ' and ` are interchanged on the mysql statement, then it can cause the supplied argument error (or that's what I think is the first thing you should check).
The administrator has disabled public write access.

Re: Setup form so each user can only submit once ? 11 years 8 months ago #18111

  • shorton
  • shorton's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
  • Thank you received: 1
I know this topic is old but I found a work around for anyone having issues getting this to work. Basically it querys the specified database to count how many times a user's id shows up in relation to the form number. If it is greater or equal to 1 then it returns the message. This goes in the "Script called on form display" section of your form and is working as of RSForm version 2.5.4
global $database;
$rsuser = JFactory::getUser();
$id = $rsuser->get('id'); 
$database = JFactory::getDBO();
$database->setQuery("SELECT COUNT(`SubmissionId`) FROM jos_rsform_submissions WHERE UserId=$id AND FormId='3'");
$database->query();
if (intval($database->loadResult()) >= 1)
{
     echo 'You have already completed this form!';
     $formLayout = '';
} 
The administrator has disabled public write access.
The following user(s) said Thank You: darkrage000

Re: Setup form so each user can only submit once ? 11 years 2 months ago #20748

This worked GREAT. Thanks.

(remeber to change your form ID AND your jos_ database prefix)
The administrator has disabled public write access.

Re: Setup form so each user can only submit once ? 11 years 2 months ago #21031

  • Spieth
  • Spieth's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 1
shorton wrote:
I know this topic is old but I found a work around for anyone having issues getting this to work. Basically it querys the specified database to count how many times a user's id shows up in relation to the form number. If it is greater or equal to 1 then it returns the message. This goes in the "Script called on form display" section of your form and is working as of RSForm version 2.5.4
global $database;
$rsuser = JFactory::getUser();
$id = $rsuser->get('id'); 
$database = JFactory::getDBO();
$database->setQuery("SELECT COUNT(`SubmissionId`) FROM jos_rsform_submissions WHERE UserId=$id AND FormId='3'");
$database->query();
if (intval($database->loadResult()) >= 1)
{
     echo 'You have already completed this form!';
     $formLayout = '';
} 

Hi all of you,

This script works fine but I need one which refers to the user Ip, because the other ones in this post doesn´t work for me.

Could anybody help me, please?

Thanks so much
The administrator has disabled public write access.

Setup form so each user can only submit once ? 11 years 2 months ago #21060

  • Spieth
  • Spieth's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 1
Hi again, I did it!!!

Thanks so much

If anybody needs the code here it is.

$rsip =$_SERVER['REMOTE_ADDR'];
$database = JFactory::getDBO(); 
$database->setQuery("SELECT COUNT(`SubmissionId`) FROM jos_rsform_submissions WHERE `UserIP`='".$rsip."'AND FormId='15'");
$database->query();
if (intval($database->loadResult()) >= 1)
{
     echo 'Usted ya ha completado esta encuesta!';
     $formLayout = '';
} 

See you
The administrator has disabled public write access.
The following user(s) said Thank You: paypal708

Setup form so each user can only submit once ? 10 years 10 months ago #23157

I need to be able to limit by IP address as my form submitters are not registered users and I am on version 1.4.0 R43. Does anyone know the php script I would use to do that?
The administrator has disabled public write access.

Setup form so each user can only submit once ? 10 years 2 months ago #26168

  • Langust
  • Langust's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Spieth wrote:
Hi again, I did it!!!

Thanks so much

If anybody needs the code here it is.

Thank you so much!
This is what we need!
Works fine.
(1.4.0. rev 44)
The administrator has disabled public write access.

Setup form so each user can only submit once ? 10 years 3 weeks ago #26734

  • info1593
  • info1593's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 14
Hi...

I know this topic is a bit old, but how does the script look if I want to check the e-mail address instead of the ip?

I'm using the RSform Pro R48.

Thanks!
The administrator has disabled public write access.

Setup form so each user can only submit once ? 9 years 11 months ago #27289

Hello there,

I need to check my submissions and see if a submission has been made with same field entry. Its the same that you mention with the e-mail, but instead of e-mail i need to check with another field called code.

So i use this code:
$rsid = $_POST['form']['code'];
$foundValid = false;
if (mysql_num_rows(mysql_query("SELECT SubmissionId FROM  myprefix_RSFORM_SUBMISSION_VALUES WHERE FieldValue=$rsid AND FormId='22' LIMIT 1")) > 0)
$foundValid = true;
if($foundValid == true)
{
$invalid[]=RSresolveComponentName('code',$formId);
echo "<p style='color:red; font-size:14px; font-weight:800;'>". "You have completed this form again with the Code:" . "&nbsp;" . $rsid ."</p>";
}

but it appears that whatever i try to enter as the code i get the error, even if i haven't completed the form with a code.

Any ideas?
The administrator has disabled public write access.

Setup form so each user can only submit once ? 8 years 7 months ago #31978

  • modiac
  • modiac's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
Hello,

Though its a pretty old 2010 forum post
But - The code originally posted for restricting user submission to once - does not work in
Pls advise for modification for same
The administrator has disabled public write access.

Setup form so each user can only submit once ? 8 years 7 months ago #31987

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

RSForm!Pro 'Custom scripting' documentation section has expanded over time. You'll find various examples such as the followings:

- Limit the overall number of submissions to a form

- Limit the number of submissions based on the user's IP address

- Limit the number of submissions based on the logged in username
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.

Setup form so each user can only submit once ? 8 years 4 months ago #33020

  • web.admin
  • web.admin's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 2
Dear All

I would like to limit the submit information 1 time by email with a limit on 24h.
How can I do?

Thank you very much
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!