• Resolved logicelf

    (@logicelf)


    Hi folks,

    I’m building a community interest site (free, non-profit) with Forminator and GamiPress. The site is a replacement for an old ‘DIY’ iOS app, which is awful. Each month has a ‘theme’ for members. Forminator is great for the site managers, because it’s easy for them to configure – I have it running several features for them. However, each month they do a quiz with 5 questions, which you pass if you get 3 or more correct. A point is then awarded (points are just for fun).

    I can’t see any hooks in Forminator that are related to ‘pass’ or ‘fail’ threshold for the quiz type forms – which seems odd, unless I’m missing something?

    I want the site managers to be able to post a quiz, set a pass threshold, and for GamiPress to detect a relevent event to hook into in order to award the member a point.

    I’d rather stick with Forminator, as it’s very user-friendly for them – but unless I can find a way of triggering an action of some sort, I’ll have to try to find something else to do the quizzes.

    Any ideas about this – especially from the Forminator team – would really be appreciated!

    Thanks in advance,

    James

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @logicelf ,

    Thank you for the nice words about Forminator.

    I will check with our developers if there are hooks that would be useful for you and let you know.

    kind regards,
    Kasia

    Thread Starter logicelf

    (@logicelf)

    Thanks Kasia!

    Thread Starter logicelf

    (@logicelf)

    Hi @wpmudev-support2 – any news on this?

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @logicelf

    I apologies for the delay here, It seems our developers missed the ping.

    I pinged them again and we will update once hearing back from the team.

    Best Regards
    Patrick Freitas

    Thread Starter logicelf

    (@logicelf)

    Thanks Patrick!

    Thread Starter logicelf

    (@logicelf)

    @wpmudev-support2 or @wpmudevsupport12 – anything yet?

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @logicelf ,

    There are no filters for that I’m afraid. We have only an older js snippet for knowledge quizzes, that can be used to redirect to a specific page if a required number of answers is correct. Here’s the snippet:

    add_action( 'wp_footer', function(){
    	global $post;
    	if ( ! $post instanceof WP_Post || ! has_shortcode( $post->post_content, 'forminator_quiz' ) ) {
    		return;
    	}
    	$score = 3;
    	$redirect_to = 'https://site.com/success_page';
    	?>
    	<script type="text/javascript">
    		(($,d)=>{
    			if ( window.forminator_quiz_result_monitor ) {
    				return;
    			}
    			window.forminator_quiz_result_monitor = {
    				nonce: '<?php echo wp_create_nonce( "wpmudev_smush_single_image" ); ?>',
    				init: function() {
    					$(d).ajaxComplete( function( event, xhr, settings ) {
    						let _this = forminator_quiz_result_monitor;
    						if ( 'forminator_submit_form_quizzes' !== _this.get_query_var( 'action', unescape( settings.data ) ) ) {
    							return;
    						}
    						let response_text = JSON.parse( xhr.responseText ),
    							score_limit = <?php echo $score; ?>,
    							redirect_to = '<?php echo $redirect_to; ?>',
    							correct_answers = 0,
    							incorrect_answers = 0;
    						if ( 
    							typeof response_text.data === 'undefined' ||
    							typeof response_text.data.result === 'undefined'
    						) {
    							return;
    						}
    						for( var key in response_text.data.result ) {
    							if ( response_text.data.result[key]['isCorrect'] ) {
    								correct_answers++;
    							} else {
    								incorrect_answers++;
    							}
    						}
    						if ( correct_answers >= score_limit ) {
    							window.location.replace( redirect_to );
    						}
    					});                    
    				},
    				get_query_var: function( name, url ) {
    					if ( ! url ) {
    						return false;
    					}
    					name = name.replace(/[\[\]]/g, "\\$&");
    					var regex = new RegExp(name + "(=([^&#]*)|&|#|$)"),
    						results = regex.exec(url);
    					//if (!results) return false;
    					if (!results[2]) return false;
    					return decodeURIComponent( results[2].replace(/\+/g, " ") );
    				}
    			};
    			$(d).ready( function(){
    				forminator_quiz_result_monitor.init();
    			} );
    		})(jQuery,document);
    	</script>
    	<?php
    }, 9999 );

    kind regards,
    Kasia

    Thread Starter logicelf

    (@logicelf)

    Hi @wpmudev-support2 ,

    Apologies for the late reply. That seems odd to me – surely the entire point of a quiz is to determine whether the person taking it passes or fails it …?

    Thanks for the snippet (I can at least create a custom hook with this), but may I make a feature request for the ability for the person authoring the quiz to set a pass mark (and for the trigger to be exposed so that plugins like GamiPress can hook into it)?

    Thanks!

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @logicelf

    I hope you are doing well.

    GamiPress has an add-on for Forminator: https://www.ads-software.com/plugins/gamipress-forminator-integration/

    I’m afraid I don’t know the available hooks on the add-on to tell what can be done using the hooks.

    However, I’m certainly passing this ticket to our developers as a feature request, I can see some improvements for the Quiz coming.

    I’m also making this ticket as resolved, however, feel free to let us know if you have any additional question.

    Best Regards
    Patrick Freitas

    Thread Starter logicelf

    (@logicelf)

    Hi @wpmudevsupport12

    Thanks for the reply. I have the GamiPress add-on for Forminator installed, which is how I’m managing point allocations against the the other events. The issue, per my original post, is that (while it has other Forminator events to hook into) it has no events in Forminator to hook into in order to tell how many points were earned on a quiz, or whether the result was a ‘pass’ or ‘fail’ (a property which I really consider to be an intrinsic quality of a quiz).

    Thanks for passing this on to the dev team. I’d be grateful if you’d pass back any info on their thoughts/intentions and/or an ETA for a pass/fail threshold, as I don’t want to waste hours coding something custom if it’s going to be added relatively soon!

    I appreciate your wanting to close the ticket, but – with respect – I don’t consider it ‘resolved’ at this point.

    Thanks again,

    James

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @logicelf,

    I think it’s possible – a bit like it’s done in the extension in gamipress_forminator_quiz_completion_listener

    just by looping all the answers on
    forminator_quizzes_submit_before_set_fields

    whether the result was a ‘pass’ or ‘fail’ (a property which I really consider to be an intrinsic quality of a quiz).

    This depends on the login you have on your mind. If all or none logic – then it’s already done. If not – you can override
    gamipress_forminator_quiz_completion_listener

    Our SLS folks wrote aa simple mu-plugin which could help you get the pass or fail. Here is the code for the same:

    <?php
    /**
     * Plugin Name: [Forminator Pro] - different quiz response based on score
     * Plugin URI: https://premium.wpmudev.org/
     * Description: 
     * Author: Maciej Palmowski @ WPMUDEV
     * Author URI: https://premium.wpmudev.org/
     * Task: SLS-110
     * License: GPLv2 or later
     */
    
    add_filter(
    	'forminator_quizzes_render_knowledge_result',
    	function( $knowledge_result_html, $text, $model ) {
    		$pattern = '/([0-9]+)(\/)([0-9]+)/';
    		preg_match( $pattern, $text, $matches );
    
    		$correct = (int) $matches[1];
    		$all     = (int) $matches[3];
    
    		$percentage = $correct / $all * 100;
    
    		$ret = '<div role="alert" class="forminator-quiz--summary">';
    		if ( $percentage >= 80 ) {
    			$ret .= 'success';
    		} else {
    			$ret .= 'fail';
    		}
    		$ret .= '</div>';
    
    		return $ret;
    	},
    	10,
    	3
    );

    Do remember to change the following in the responses part:

    
    if ( $percentage >= 80 ) {
    	$ret .= 'success';
    } else {
    	$ret .= 'fail';
    }

    Do let me know your views on the same.

    Thank you,
    Prathamesh Palve

    Thread Starter logicelf

    (@logicelf)

    Hi @wpmudev-support7

    Oh, that’s interesting – thanks very much for that, I’ll have a play!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Quizzes: Pass or fail threshold and triggers’ is closed to new replies.