Please forgive me because I'm pretty much a layman to PHP, but every now and then it's enough to turn me where necessary. But now I'm stuck and I'd be very grateful if you could give me a light.
I have a code that I can use in RSForm of Joomla that limits the number of submissions that any user can make in a due form. This part works quietly and, as I want, limits sending to one form per user.
However, my question is: Since I use this same form for sending on several different pages, how would I limit the sending of users, also taking into account the page that the user is sending?
The expected end result is that each user can submit one per page where they have access to the form!
I have this code that already limits to a per-user submission, I just need it to take the page into account:
// Define the maximum number of submissions.
$max = 1;
// Get the current logged in user.
$user = JFactory::getUser();
// Get a database connection.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Setup the query.
$query->select('COUNT('.$db->qn('Username').')')
->from($db->qn('#__rsform_submissions'))
->where($db->qn('FormId').'='.$db->q($formId))
->where($db->qn('Username').'='.$db->q($user->get('username')));
// You can also count by User ID, just replace the above with:
// ->where($db->qn('UserId').'='.$db->q($user->get('id')));
$db->setQuery($query);
$counter = $db->loadResult();
if ($counter >= $max){
$formLayout = 'Sorry, you have reached the maximum number of submissions for this form.';
}
Thanks to anyone who can help!
EDIT:
More information. These forms will always be on a K2 item page. I found that I can by PHP identify the K2 item id of the current page like this:
$K2Itemid = JRequest::getInt('id');
Could anyone help me use this information to limit sending via the K2 ID? Suddenly it's a condition to add in code.