From df560bcd927046762f3673b3d934c68dcc748543 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Thu, 23 May 2024 17:46:45 +0530 Subject: [PATCH 01/18] Multi slide polar question code changes --- js/qsm-admin.js | 6 +++++- js/qsm-common.js | 6 ++++-- php/question-types/qsm-question-type-polar.php | 8 ++++++-- php/template-variables.php | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index d366354e5..31a458fb3 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -3209,7 +3209,11 @@ var import_button; var questionType = $('#question_type').val(); var answer_length = $('#answers').find('.answers-single').length; var answerType = $('#change-answer-editor').val(); - if (answer_length > 1 && $('#question_type').val() == 13) { + let isMultiPolar = { + isActive: false, + } + jQuery(document).trigger('qsm_new_answer_button_before', [isMultiPolar, question_id]); + if (answer_length > 1 && $('#question_type').val() == 13 && !isMultiPolar.isActive) { alert(qsm_admin_messages.polar_options_validation); return; } diff --git a/js/qsm-common.js b/js/qsm-common.js index 936a1eb97..bd79f5398 100644 --- a/js/qsm-common.js +++ b/js/qsm-common.js @@ -51,8 +51,10 @@ function qsmPolarSlider(page , polarQuestions){ polarQuestions.each( function(){ let polarQuestion = jQuery(this).find('.slider-main-wrapper div'); - let questionID = polarQuestion.attr('id').replace('slider-',''); - qsmPolarSliderEach(polarQuestion,questionID,page); + if(polarQuestion.length > 0){ + let questionID = polarQuestion.attr('id').replace('slider-',''); + qsmPolarSliderEach(polarQuestion,questionID,page); + } }); } diff --git a/php/question-types/qsm-question-type-polar.php b/php/question-types/qsm-question-type-polar.php index 2d562ca16..ddc26ad4d 100644 --- a/php/question-types/qsm-question-type-polar.php +++ b/php/question-types/qsm-question-type-polar.php @@ -41,9 +41,12 @@ function qmn_polar_display( $id, $question, $answers ) { } $new_question_title = $mlwQuizMasterNext->pluginHelper->get_question_setting( $id, 'question_title' ); qsm_question_title_func( $question, '', $new_question_title, $id ); - + $show = true; + $show = apply_filters( 'qsm_check_advance_polar_show_status', $show, $id ); ?> +
+
"; $question = $input_text; $question_display .= "" . do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) . ''; - return apply_filters( 'qmn_polar_display_front', $question_display, $id, $question, $answers ); + // return apply_filters( 'qmn_polar_display_front', $question_display, $id, $question, $answers ); + return apply_filters( 'qmn_polar_display_result_page', $question_display, $id, $question, $answers, $answer ); } /** From c7576a3408fdbefeb7bfa106dac61cdc2db4b975 Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Mon, 10 Jun 2024 12:50:49 +0530 Subject: [PATCH 02/18] skip result page apply_filter data sanitization --- php/classes/class-qsm-results-pages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/classes/class-qsm-results-pages.php b/php/classes/class-qsm-results-pages.php index c1f6279c5..9d58d71a1 100644 --- a/php/classes/class-qsm-results-pages.php +++ b/php/classes/class-qsm-results-pages.php @@ -177,12 +177,12 @@ public static function generate_pages( $response_data ) { // Decodes special characters, runs through our template // variables, and then outputs the text. - $page = htmlspecialchars_decode( $content, ENT_QUOTES); + $page = wp_kses_post( htmlspecialchars_decode( $content, ENT_QUOTES) ); //last chance to filter $page $page = apply_filters( 'qsm_template_variable_results_page', $page, $response_data ); - echo wp_kses_post( apply_filters( 'mlw_qmn_template_variable_results_page', $page, $response_data ) ); + echo apply_filters( 'mlw_qmn_template_variable_results_page', $page, $response_data ); do_action( 'qsm_after_results_page', $response_data, $page_index ); ?> Date: Wed, 12 Jun 2024 16:40:25 +0530 Subject: [PATCH 03/18] fixed contact form email allow domain validation --- php/classes/class-qsm-contact-manager.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/php/classes/class-qsm-contact-manager.php b/php/classes/class-qsm-contact-manager.php index 35cd74e38..d644d84b4 100644 --- a/php/classes/class-qsm-contact-manager.php +++ b/php/classes/class-qsm-contact-manager.php @@ -353,6 +353,25 @@ public static function save_fields( $quiz_id, $fields ) { $fields[ $i ]['label'] = $label; $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $label, "quiz_contact_field_text-{$i}-{$quiz_id}" ); $mlwQuizMasterNext->pluginHelper->qsm_register_language_support( $placeholder, "quiz_contact_field_placeholder-{$i}-{$quiz_id}" ); + + // Validate allowed domains + if ( ! empty( $fields[ $i ]['allowdomains'] ) ) { + $allowdomains = explode( ',', $fields[ $i ]['allowdomains'] ); + // Trim domains + $allowdomains = array_map( 'trim', $allowdomains ); + // filter domain + $allowdomains = array_filter( $allowdomains, function( $allowdomain ) { + /** + * full domain name may not exceed a total length of 253 ASCII characters + * The domain name consists of valid labels (1-63 characters of letters, digits, + * or hyphens) followed by a dot. The domain ends with a valid TLD + * (2-63 characters of letters). + */ + return preg_match( '/^([a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}$/', $allowdomain ) && ( strlen( $allowdomain ) <= 253 ); + } ); + + $fields[ $i ]['allowdomains'] = implode( ',', $allowdomains ); + } if ( ! empty( $fields[ $i ]['options'] ) ) { $options = sanitize_text_field( wp_unslash( $fields[ $i ]['options'] ) ); $fields[ $i ]['options'] = $options; From 36fdbd122d8fc844934c91791ac773f0672fd582 Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Thu, 13 Jun 2024 11:51:14 +0530 Subject: [PATCH 04/18] Fixed: wpApiSettings JS error --- mlw_quizmaster2.php | 3 ++- readme.txt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 242550b1d..97e9fe400 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -473,7 +473,8 @@ public function qsm_admin_scripts_style( $hook ) { } } // load admin JS after all dependencies are loaded - wp_enqueue_script( 'qsm_admin_js', plugins_url( 'js/qsm-admin.js', __FILE__ ), array( 'jquery', 'backbone', 'underscore', 'wp-util', 'jquery-ui-sortable', 'jquery-touch-punch', 'qsm-jquery-multiselect-js' ), $this->version, true ); + /** Fixed wpApiSettings is not defined js error by using 'wp-api-request' core script to allow the use of localized version of wpApiSettings. **/ + wp_enqueue_script( 'qsm_admin_js', plugins_url( 'js/qsm-admin.js', __FILE__ ), array( 'jquery', 'backbone', 'underscore', 'wp-util', 'jquery-ui-sortable', 'jquery-touch-punch', 'qsm-jquery-multiselect-js', 'wp-api-request' ), $this->version, true ); wp_enqueue_style( 'jquer-multiselect-css', QSM_PLUGIN_CSS_URL . '/jquery.multiselect.min.css', array(), $this->version ); wp_enqueue_script( 'qsm-jquery-multiselect-js', QSM_PLUGIN_JS_URL . '/jquery.multiselect.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( 'micromodal_script', plugins_url( 'js/micromodal.min.js', __FILE__ ), array( 'jquery', 'qsm_admin_js' ), $this->version, true ); diff --git a/readme.txt b/readme.txt index d78e51d99..29fd3533b 100644 --- a/readme.txt +++ b/readme.txt @@ -163,6 +163,10 @@ This is usually a theme conflict. You can [checkout out our common conflict solu 18. Database == Changelog == += 9.0.5 ( Beta ) = +* Fixed: quiz contact form email allow domains validation +* Fixed: wpApiSettings JS error + = 9.0.4 ( June 10, 2024 ) = * Enhancement: Improved HTML code management on the result page From c87886a08d9ac026d5e61b2335db9a4264240bb5 Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Thu, 13 Jun 2024 16:10:32 +0530 Subject: [PATCH 05/18] Fixed: Email subject converts & to & --- php/classes/class-qsm-emails.php | 4 ++++ readme.txt | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/php/classes/class-qsm-emails.php b/php/classes/class-qsm-emails.php index ffd3599ff..7565c5bf4 100644 --- a/php/classes/class-qsm-emails.php +++ b/php/classes/class-qsm-emails.php @@ -40,6 +40,10 @@ public static function send_emails( $transient_id ) { foreach ( $emails as $index => $email ) { $email_subject = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $email['subject'], "quiz-email-subject-{$index}-{$response_data['quiz_id']}" ); + + // kses converts ampersands to & core.trac.wordpress.org/ticket/11311. + $email_subject = str_replace( '&', '&', $email_subject ); + $email_content = $mlwQuizMasterNext->pluginHelper->qsm_language_support( $email['content'], "quiz-email-content-{$index}-{$response_data['quiz_id']}" ); // Checks if any conditions are present. Else, send it always. if ( ! empty( $email['conditions'] ) ) { diff --git a/readme.txt b/readme.txt index 29fd3533b..9766b60ce 100644 --- a/readme.txt +++ b/readme.txt @@ -164,8 +164,9 @@ This is usually a theme conflict. You can [checkout out our common conflict solu == Changelog == = 9.0.5 ( Beta ) = -* Fixed: quiz contact form email allow domains validation +* Fixed: Quiz contact form email allow domains validation * Fixed: wpApiSettings JS error +* Fixed: Email subject converts & to & = 9.0.4 ( June 10, 2024 ) = * Enhancement: Improved HTML code management on the result page From 653528c18f9e4c3c20c1012fadf6279304caa544 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Thu, 13 Jun 2024 16:29:06 +0530 Subject: [PATCH 06/18] code changes for Advance polar --- js/qsm-common.js | 6 ++---- php/question-types/qsm-question-type-polar.php | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/js/qsm-common.js b/js/qsm-common.js index 6c6431c89..c2e254bc4 100644 --- a/js/qsm-common.js +++ b/js/qsm-common.js @@ -51,10 +51,8 @@ function qsmPolarSlider(page , polarQuestions){ polarQuestions.each( function(){ let polarQuestion = jQuery(this).find('.slider-main-wrapper div'); - if(polarQuestion.length > 0){ - let questionID = polarQuestion.attr('id').replace('slider-',''); - qsmPolarSliderEach(polarQuestion,questionID,page); - } + let questionID = polarQuestion.attr('id').replace('slider-',''); + qsmPolarSliderEach(polarQuestion,questionID,page); }); } diff --git a/php/question-types/qsm-question-type-polar.php b/php/question-types/qsm-question-type-polar.php index b94e88823..d078b7a5d 100644 --- a/php/question-types/qsm-question-type-polar.php +++ b/php/question-types/qsm-question-type-polar.php @@ -43,10 +43,9 @@ function qmn_polar_display( $id, $question, $answers ) { qsm_question_title_func( $question, '', $new_question_title, $id ); $show = true; $show = apply_filters( 'qsm_check_advance_polar_show_status', $show, $id ); + if ( $show ) { ?> -
-
Date: Thu, 13 Jun 2024 16:34:20 +0530 Subject: [PATCH 07/18] Fixed blank date field in contact form --- php/classes/class-qmn-plugin-helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/classes/class-qmn-plugin-helper.php b/php/classes/class-qmn-plugin-helper.php index 88ece3223..d6c6ffaee 100644 --- a/php/classes/class-qmn-plugin-helper.php +++ b/php/classes/class-qmn-plugin-helper.php @@ -1097,7 +1097,7 @@ public function convert_contacts_to_preferred_date_format( $qsm_qna_array ) { $qsm_contact_array = $qsm_qna_array['contact']; foreach ( $qsm_contact_array as $qsm_contact_id => $qsm_contact ) { - if ( 'date' === $qsm_contact['type'] && null !== $GLOBALS['qsm_date_format'] ) { + if ( 'date' === $qsm_contact['type'] && '' !== $qsm_contact['value'] && null !== $GLOBALS['qsm_date_format'] ) { $qsm_qna_array['contact'][ $qsm_contact_id ]['value'] = date_i18n( $GLOBALS['qsm_date_format'], strtotime( ( $qsm_contact['value'] ) ) ); } } From ae2adb7a92c34167950158f604f36b85d37595a2 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Thu, 13 Jun 2024 17:05:04 +0530 Subject: [PATCH 08/18] Fixed contact tab UI issue --- css/qsm-admin.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/qsm-admin.css b/css/qsm-admin.css index a0da07f7b..2d6a3dc7d 100644 --- a/css/qsm-admin.css +++ b/css/qsm-admin.css @@ -2683,7 +2683,7 @@ input#duplicate_questions { flex-wrap: wrap; justify-content: flex-start; align-content: flex-start; - margin-bottom: 150px; + margin-bottom: 250px; } .contact-form-builder-wrap a { display: inline-block; From 8cda5979b392b2582d478da56588cefacff9e5ab Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Fri, 14 Jun 2024 16:08:21 +0530 Subject: [PATCH 09/18] Added hook and code changes for Advance Polar --- php/question-types/qsm-question-type-polar.php | 1 + php/template-variables.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/php/question-types/qsm-question-type-polar.php b/php/question-types/qsm-question-type-polar.php index d078b7a5d..3113fe1cc 100644 --- a/php/question-types/qsm-question-type-polar.php +++ b/php/question-types/qsm-question-type-polar.php @@ -43,6 +43,7 @@ function qmn_polar_display( $id, $question, $answers ) { qsm_question_title_func( $question, '', $new_question_title, $id ); $show = true; $show = apply_filters( 'qsm_check_advance_polar_show_status', $show, $id ); + echo apply_filters( 'qmn_polar_display_front_before', '', $id, $question, $answers ); if ( $show ) { ?> diff --git a/php/template-variables.php b/php/template-variables.php index 351c26142..bd1545d11 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -1557,7 +1557,7 @@ function qmn_polar_display_on_resultspage( $id, $question, $answers, $answer ) { $input_text .= ""; $question = $input_text; $question_display .= "" . do_shortcode( htmlspecialchars_decode( $question, ENT_QUOTES ) ) . ''; - // return apply_filters( 'qmn_polar_display_front', $question_display, $id, $question, $answers ); + $question_display = apply_filters( 'qmn_polar_display_front', $question_display, $id, $question, $answers ); return apply_filters( 'qmn_polar_display_result_page', $question_display, $id, $question, $answers, $answer ); } From 9edbbcfe013930e35e348404f8e95bf543c8ebbc Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Fri, 14 Jun 2024 16:12:46 +0530 Subject: [PATCH 10/18] Added hook and code changes for Advance Polar --- php/question-types/qsm-question-type-polar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/question-types/qsm-question-type-polar.php b/php/question-types/qsm-question-type-polar.php index 3113fe1cc..d471991dc 100644 --- a/php/question-types/qsm-question-type-polar.php +++ b/php/question-types/qsm-question-type-polar.php @@ -145,5 +145,5 @@ function qmn_polar_review( $id, $question, $answers ) { /** * Hook to filter answers array */ - return apply_filters( 'qmn_polar_review', $return_array, $id, $question, $answers ); + return apply_filters( 'qmn_polar_review', $return_array, $answers ); } \ No newline at end of file From aee0310da7dd08c8e907e6fbd3a6069689eb985f Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Tue, 18 Jun 2024 13:23:39 +0530 Subject: [PATCH 11/18] Fix contact tab UI and behaviour --- css/common.css | 2 +- js/qsm-admin.js | 24 +++++++++++++++++++++++ php/classes/class-qsm-contact-manager.php | 14 ++++++------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/css/common.css b/css/common.css index 78469a2da..d91d2bf8f 100644 --- a/css/common.css +++ b/css/common.css @@ -256,7 +256,7 @@ footer.qsm-popup__footer button.qsm-popup-secondary-button:hover { align-content: center; } .qsm-quiz-container .qsm-contact-type-checkbox input { - margin: 0 5px 0 3px; + margin: 0 5px 6px 3px; } .mlw_qmn_question_number { font-weight: bold; diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 62b2d07c4..7d5004b2f 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -4115,4 +4115,28 @@ var import_button; }); } ); +}(jQuery)); + +(function ($) { + $(document).ready(function() { + var $settingsFields = $('.settings-field'); + var $popups = $('.qsm-contact-form-field-settings'); + + // Function to hide all popups + function hideAllPopups() { + $popups.hide(); + } + + // Close popup on document click if popup is open and clicking outside + $(document).on('click', function(event) { + if (!$settingsFields.is(event.target) && $settingsFields.has(event.target).length === 0) { + hideAllPopups(); + } + }); + + // Prevent the click event from propagating to the document when clicking inside the popup + $popups.on('click', function(event) { + event.stopPropagation(); + }); + }); }(jQuery)); \ No newline at end of file diff --git a/php/classes/class-qsm-contact-manager.php b/php/classes/class-qsm-contact-manager.php index d644d84b4..70e7ba61d 100644 --- a/php/classes/class-qsm-contact-manager.php +++ b/php/classes/class-qsm-contact-manager.php @@ -413,6 +413,8 @@ public static function generate_contact_field( $field, $index, $quiz_options, $d $class .= ' mlwRequiredRadio '; }elseif ( 'select' === $field["type"] ) { $class .= 'qsmRequiredSelect'; + }elseif ( 'number' === $field["type"] ) { + $class .= 'mlwRequiredNumber'; }else { $class .= 'mlwRequiredText qsm_required_text'; if ( 'checkbox' === $field["type"] ) { @@ -552,7 +554,7 @@ public static function generate_contact_field( $field, $index, $quiz_options, $d ?> - maxlength='' oninput='maxLengthCheck(this)' /> + maxlength='' oninput='maxLengthCheck(this)' />
@@ -589,8 +591,8 @@ class="qmn_quiz_radio"
'; + } break; case 'select': // Filer Value @@ -601,7 +603,7 @@ class="qmn_quiz_radio" $fieldAttr .= " autocomplete='off' "; } // If REQUIRED is set then assigning the required class - if ( isset( $field['options'] ) ) { + if ( isset( $field['options'] ) && !empty( trim( $field['options'] ) ) ) { ?> - Date: Tue, 18 Jun 2024 14:31:33 +0530 Subject: [PATCH 12/18] Fix contact tab UI and behaviour --- js/qsm-admin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 7d5004b2f..a6f76188a 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -4123,14 +4123,14 @@ var import_button; var $popups = $('.qsm-contact-form-field-settings'); // Function to hide all popups - function hideAllPopups() { + function qsmHideAllPopups() { $popups.hide(); } // Close popup on document click if popup is open and clicking outside $(document).on('click', function(event) { if (!$settingsFields.is(event.target) && $settingsFields.has(event.target).length === 0) { - hideAllPopups(); + qsmHideAllPopups(); } }); From a370b075d924f8febb2cc0ade0e13d427237e189 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Wed, 19 Jun 2024 12:00:28 +0530 Subject: [PATCH 13/18] Fixed contact field visibility on result page --- css/common.css | 2 +- php/template-variables.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/css/common.css b/css/common.css index d91d2bf8f..3dead6e27 100644 --- a/css/common.css +++ b/css/common.css @@ -256,7 +256,7 @@ footer.qsm-popup__footer button.qsm-popup-secondary-button:hover { align-content: center; } .qsm-quiz-container .qsm-contact-type-checkbox input { - margin: 0 5px 6px 3px; + margin: 0 5px 9px 3px; } .mlw_qmn_question_number { font-weight: bold; diff --git a/php/template-variables.php b/php/template-variables.php index bd1545d11..40edfb8c2 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -508,10 +508,21 @@ function qsm_contact_field_variable( $content, $results_array ) { * @return string The HTML for the content */ function qsm_all_contact_fields_variable( $content, $results ) { + global $mlwQuizMasterNext; + $contact_form = $mlwQuizMasterNext->pluginHelper->get_quiz_setting( 'contact_form' ); + $return = ''; if ( isset( $results['contact'] ) && ( is_array( $results['contact'] ) || is_object( $results['contact'] ) ) ) { for ( $i = 0; $i < count( $results['contact'] ); $i++ ) { - $return .= $results['contact'][ $i ]['label'] . ': ' . $results['contact'][ $i ]['value'] . '
'; + $results_contact = $results['contact'][ $i ]; + $options = array_filter($contact_form, function( $results_contact ) use ($label, $type) { + return $results_contact['label'] === $label && $results_contact['type'] === $type; + })['options'] ?? null; + if ( in_array($results['contact'][ $i ]['type'], ['radio', 'select']) && !empty(trim($options)) ) { + $return .= $results['contact'][ $i ]['label'] . ': ' . $results['contact'][ $i ]['value'] . '
'; + } elseif ( !in_array($results['contact'][ $i ]['type'], ['radio', 'select']) ) { + $return .= $results['contact'][ $i ]['label'] . ': ' . $results['contact'][ $i ]['value'] . '
'; + } } } $content = str_replace( '%CONTACT_ALL%', $return, $content ); From 114c7a7d318e6d236a26341d3540d9b137478101 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Wed, 19 Jun 2024 12:49:17 +0530 Subject: [PATCH 14/18] Fixed contact field visibility on result page --- php/template-variables.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/php/template-variables.php b/php/template-variables.php index 40edfb8c2..39b3ad26b 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -513,22 +513,26 @@ function qsm_all_contact_fields_variable( $content, $results ) { $return = ''; if ( isset( $results['contact'] ) && ( is_array( $results['contact'] ) || is_object( $results['contact'] ) ) ) { - for ( $i = 0; $i < count( $results['contact'] ); $i++ ) { - $results_contact = $results['contact'][ $i ]; - $options = array_filter($contact_form, function( $results_contact ) use ($label, $type) { - return $results_contact['label'] === $label && $results_contact['type'] === $type; - })['options'] ?? null; - if ( in_array($results['contact'][ $i ]['type'], ['radio', 'select']) && !empty(trim($options)) ) { - $return .= $results['contact'][ $i ]['label'] . ': ' . $results['contact'][ $i ]['value'] . '
'; - } elseif ( !in_array($results['contact'][ $i ]['type'], ['radio', 'select']) ) { - $return .= $results['contact'][ $i ]['label'] . ': ' . $results['contact'][ $i ]['value'] . '
'; + foreach ( $results['contact'] as $results_contact ) { + $options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] ); + if ( in_array($results_contact['type'], ['radio', 'select']) && !empty(trim($options)) ) { + $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; + } elseif ( !in_array($results_contact['type'], ['radio', 'select']) ) { + $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; } } } $content = str_replace( '%CONTACT_ALL%', $return, $content ); return $content; } - +function qsm_get_options_of_contact_fields($data, $label, $type) { + foreach ($data as $item) { + if ($item['label'] === $label && $item['type'] === $type) { + return $item['options']; + } + } + return null; // Option not found +} /** * Converts the %QUESTIONS_ANSWERS% into the template * From d0ff0d570290e628a5bdc6dcd814c18eb27e4248 Mon Sep 17 00:00:00 2001 From: PranavAwasthi Date: Wed, 19 Jun 2024 13:17:32 +0530 Subject: [PATCH 15/18] Fixed contact field visibility on result page --- php/template-variables.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/php/template-variables.php b/php/template-variables.php index 39b3ad26b..b1c22ce30 100644 --- a/php/template-variables.php +++ b/php/template-variables.php @@ -515,9 +515,10 @@ function qsm_all_contact_fields_variable( $content, $results ) { if ( isset( $results['contact'] ) && ( is_array( $results['contact'] ) || is_object( $results['contact'] ) ) ) { foreach ( $results['contact'] as $results_contact ) { $options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] ); - if ( in_array($results_contact['type'], ['radio', 'select']) && !empty(trim($options)) ) { - $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; - } elseif ( !in_array($results_contact['type'], ['radio', 'select']) ) { + $isRadioOrSelect = in_array($results_contact['type'], ['radio', 'select']); + $hasOptions = !empty(trim($options)); + + if (($isRadioOrSelect && $hasOptions) || !$isRadioOrSelect) { $return .= $results_contact['label'] . ': ' . $results_contact['value'] . '
'; } } From 2811c1320b1f5a2fb3569f3a5be7fe3a89946d2d Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Wed, 19 Jun 2024 15:02:44 +0530 Subject: [PATCH 16/18] fixed php warning if quiz_settings are blank --- php/classes/class-qsm-contact-manager.php | 4 ++-- php/classes/class-qsm-install.php | 4 +++- php/classes/class-qsm-migrate.php | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/php/classes/class-qsm-contact-manager.php b/php/classes/class-qsm-contact-manager.php index 70e7ba61d..1b89791f1 100644 --- a/php/classes/class-qsm-contact-manager.php +++ b/php/classes/class-qsm-contact-manager.php @@ -569,7 +569,7 @@ public static function generate_contact_field( $field, $index, $quiz_options, $d /** * Add options validation */ - if ( isset( $field['options'] ) && !empty( trim( $field['options'] ) ) ) { + if ( isset( $field['options'] ) && ! empty( trim( $field['options'] ) ) ) { ?>
@@ -603,7 +603,7 @@ class="qmn_quiz_radio" $fieldAttr .= " autocomplete='off' "; } // If REQUIRED is set then assigning the required class - if ( isset( $field['options'] ) && !empty( trim( $field['options'] ) ) ) { + if ( isset( $field['options'] ) && ! empty( trim( $field['options'] ) ) ) { ?>