• 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: One Submission

One Submission 10 years 11 months ago #27782

Hi Guys,

I have a piece of script that works great on my form - allows only one submisison per user.

However I'd jusrt like to modify this slightly and include a date. My script is below, if somebody can alter it I would be happy!
// Define the maximum number of submissions.
$max = 1;
 
// Get the current logged in user.
$user = JFactory::getUser();
 
// Get a database connection.
$db = JFactory::getDbo();
 
// Setup the query.
$db->setQuery("SELECT COUNT(`Username`) FROM `#__rsform_submissions` WHERE `Username`='".$db->escape($user->username)."' AND `FormId`='".(int) $formId."'");
 
$counter = $db->loadResult();
 
if ($counter >= $max){
  $formLayout = '<p style="color:red;">' . $user->name . ', you have already entered this competition ' . $date->DateSubmitted. '.<br>Get in touch if you have any questions.</p>';
}

The code above displays Mr Jones, you have already entered this competition. Get in touch if you have any questions.

I would like it to display Mr Jones, you have already entered this competition on DATE XX-XX-XXXX. Get in touch if you have any questions.

Thanks in advance

J
The administrator has disabled public write access.

One Submission 10 years 11 months ago #27783

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
I edited your php code a little, try using this code
// Define the maximum number of submissions.
$max = 1;
 
// Get the current logged in user and get a database connection.
$db = JFactory::getDbo();
$user = JFactory::getUser();
 
// Setup the query.
$db->setQuery("SELECT COUNT(`SubmissionId`) FROM #__rsform_submissions WHERE `UserId`='". $user->get('id')."'AND `FormId`='".(int) $formId."'");
$submissions = $db->loadResult();
 
// Setup the second query for the date.
$db->setQuery("SELECT(`DateSubmitted`) FROM #__rsform_submissions WHERE `UserId`='". $user->get('id')."' AND `FormId`='".(int) $formId."' ORDER BY `SubmissionID` DESC LIMIT 1");
$date = $db->loadResult();
 
// Convert the result to be more user-friendly.
$date = date('d-m-Y',strtotime($date));
 
// Verify if the user is registered.
if ($user->get('id') == 0) {
      $formLayout = '<p>Sorry, you must be registered to enter this competition.</p>';
	 }
 
 // If he is found registered , verify if he already submitted a form.
	else if ($submissions >= $max) {
		$formLayout = '<p>Sorry '.$user->get('name').', you have already entered this competition '.$date.'</p>';
}
 
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 11 months ago by cosmin.cristea.
The administrator has disabled public write access.
The following user(s) said Thank You: johnnyboi_123

One Submission 10 years 11 months ago #27790

cosmin.cristea thank you very much - works like a charm!

I was almost there but you got it perfect. B)
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!