Login Form

#521 – Survey Module: Display Message When Survey Completed

Posted in ‘BF Survey’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
Wednesday, 04 February 2015 12:14 AEDT
ps1mpson
Joomla! version: 3.3.6

Hello,

I recently purchased BF Survey and am having an issue when trying to implement it a certain way on my site. I have monthly surveys displayed as modules on the sidebar of my site's home page which can be completed by each user at their will. There are multiple surveys dependent on the users subscription level (each one question in length), with each being displayed in its own module. Once a survey is complete, users aren't allowed to complete them a second time until new ones come out the next month. To make this happen, I set the "Prevent multiple entries (UID)" option to "Yes".

However with it set up this way, when a user completes a survey and tries to return to the homepage of my site, the page won't display due to there being too many redirects. If I remove the limitation on multiple entries, the error goes away.

What I need to happen is this:
1. User goes to home page of website where single question surveys are displayed on the front page in modules.
2. User completes survey and stays on front page.
2. Module of the survey that was submitted then displays message stating that this survey has been completed.

Is there any way to make this happen?

Thanks in advance.
Saturday, 14 February 2015 13:18 AEDT 20'
Tim
Everything Bundle, BF Quiz Plus 3 Years, BF Survey 12 Months
Hi Charles,
Sorry for the slow response on this one. The prevent multiple entries was never designed to be used for a survey in a module position. That said, I've been able to recreate the scenario on my test site, and I can see which code is causing the problem.

In the model, for instance /components/com_bfsurvey/model/3results.php (where 3 is the category id number), you will see around line 95

JError::raiseWarning( 403, JText::_( 'COM_BFSURVEY_ERROR_UID_ALREADY_COMPLETED') );
$app->redirect(JRoute::_(JURI::root().'index.php'));

If you comment out these lines, it will stop the redirect and your homepage will no longer break. However, this is going to disable the prevent multiple entries feature. Note that whenever you change the category or questions in BF Survey, it dynamically rebuilds the front end, so these changes would be overwritten. To avoid this, you could change lines 3033-3034 in /administrator/components/com_bfsurvey/helpers/answertable.php

Also note that you'd need to reapply these changes to the answer table each time you upgrade the software version in future.


So you'd then need to implement this in your module. For example:

/modules/com_bfsurvey/mod_bfsurvey.php

//line 68
F0FDispatcher::getTmpInstance('com_bfsurvey', $catid.'result', $config)->dispatch();

//change to:
$table = '#__bfsurvey_'.$catid.'results';
$user = JFactory::getUser();

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->select('preventMultiple, preventMultipleEmail, preventMultipleUID');
$query->from('#__bfsurvey_categories AS a');
$query->where('a.bfsurvey_category_id = '.(int)$catid);

$db->setQuery((string)$query);
$result = $db->loadObjectList();

$preventMultipleUID = $result[0]->preventMultipleUID;

if($user->id != "" && $user->id != 0){
$query->clear();
$query->from($db->quoteName($table));
$query->select('count(created_by)');
$query->where('created_by = '.(int) $user->id.' AND enabled>-1');

$db->setQuery((string)$query);
$result=$db->loadResult();

if($result > 0){
echo "Your user id has already complete this survey";
}else{
F0FDispatcher::getTmpInstance('com_bfsurvey', $catid.'result', $config)->dispatch();
}
}



regards

Tim
Follow us on twitter http://twitter.com/tamlynsoftware
Wednesday, 18 March 2015 15:25 AEDT
system
This ticket has been automatically closed. All tickets which have been inactive for a long time are automatically closed. If you believe that this ticket was closed in error, please contact us.
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.
Go to top