Updated quiztech-assessment-platform/public/templates/assessment-shell.php to fix the incorrect meta key (_quiztech_question_type) and align the question type handling in the switch statement with the types defined in QuestionMetaboxes.php (textarea, text, multiple-choice, checkbox, numeric)

This commit is contained in:
Ruben Ramirez 2025-04-04 08:04:40 -05:00
parent f84960326a
commit 21204d2682

View file

@ -156,7 +156,7 @@ $show_pre_screening = ! empty( $pre_screening_questions ) && is_array( $pre_scre
}
$question_title = get_the_title( $question_post );
$question_content = apply_filters('the_content', $question_post->post_content); // Get question content
$question_type = get_post_meta( $question_id, 'question_type', true );
$question_type = get_post_meta( $question_id, '_quiztech_question_type', true ); // CORRECTED META KEY
$is_first_question = ( $index === 0 ); // Check if it's the first question
?>
<div class="quiztech-question-container <?php echo $is_first_question ? '' : 'quiztech-question-hidden'; ?>"
@ -174,13 +174,17 @@ $show_pre_screening = ! empty( $pre_screening_questions ) && is_array( $pre_scre
<div class="question-answer-area">
<?php // Render input based on question type ?>
<?php switch ( $question_type ) :
case 'text': ?>
case 'textarea': // Changed from 'text' to match metabox 'Text Area (Multi-line)' ?>
<textarea name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" required></textarea>
<?php break; ?>
<?php case 'multiple-choice': ?>
<?php case 'text': // Added for metabox 'Text (Single Line)' ?>
<input type="text" name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" required>
<?php break; ?>
<?php case 'multiple-choice': // Kept as is ?>
<?php
$choices = get_post_meta( $question_id, 'question_choices', true );
$choices = get_post_meta( $question_id, 'question_choices', true ); // Assuming choices are stored with this key
if ( is_array( $choices ) && ! empty( $choices ) ) :
foreach ( $choices as $choice_index => $choice_text ) :
$choice_value = esc_attr( $choice_text ); // Use text as value for simplicity
@ -200,13 +204,35 @@ $show_pre_screening = ! empty( $pre_screening_questions ) && is_array( $pre_scre
<?php endif; ?>
<?php break; ?>
<?php case 'true-false': ?>
<label><input type="radio" name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" value="true" required> True</label><br>
<label><input type="radio" name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" value="false"> False</label>
<?php case 'checkbox': // Added for metabox 'Checkboxes (Multiple Answers)' ?>
<?php
$choices = get_post_meta( $question_id, 'question_choices', true ); // Assuming choices are stored with this key
if ( is_array( $choices ) && ! empty( $choices ) ) :
foreach ( $choices as $choice_index => $choice_text ) :
$choice_value = esc_attr( $choice_text ); // Use text as value for simplicity
$choice_id = 'choice_' . esc_attr( $question_id ) . '_' . esc_attr( $choice_index );
?>
<label for="<?php echo $choice_id; ?>">
<input type="checkbox"
id="<?php echo $choice_id; ?>"
name="assessment_answer[<?php echo esc_attr( $question_id ); ?>][]" <?php // Note the [] for multiple values ?>
value="<?php echo $choice_value; ?>"> <?php // Checkbox group might not need 'required' on individual inputs ?>
<?php echo esc_html( $choice_text ); ?>
</label><br>
<?php endforeach; ?>
<?php else : ?>
<p class="error"><?php esc_html_e( 'Error: Choices not found for this question.', 'quiztech' ); ?></p>
<?php endif; ?>
<?php break; ?>
<?php default: ?>
<p class="error"><?php esc_html_e( 'Unsupported question type.', 'quiztech' ); ?></p>
<?php case 'numeric': // Added for metabox 'Numeric' ?>
<input type="number" name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" required step="any"> <?php // step="any" allows decimals ?>
<?php break; ?>
<?php // Removed 'true-false' case as it's not defined in QuestionMetaboxes.php ?>
<?php default: // Kept as is ?>
<p class="error"><?php esc_html_e( 'Unsupported question type:', 'quiztech' ); ?> <?php echo esc_html( $question_type ); ?></p> <?php // Added type output for debugging ?>
<?php endswitch; ?>
</div> <?php // .question-answer-area ?>
</div> <?php // .quiztech-question-container ?>