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:
parent
f84960326a
commit
21204d2682
1 changed files with 35 additions and 9 deletions
|
|
@ -156,7 +156,7 @@ $show_pre_screening = ! empty( $pre_screening_questions ) && is_array( $pre_scre
|
||||||
}
|
}
|
||||||
$question_title = get_the_title( $question_post );
|
$question_title = get_the_title( $question_post );
|
||||||
$question_content = apply_filters('the_content', $question_post->post_content); // Get question content
|
$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
|
$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'; ?>"
|
<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">
|
<div class="question-answer-area">
|
||||||
<?php // Render input based on question type ?>
|
<?php // Render input based on question type ?>
|
||||||
<?php switch ( $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>
|
<textarea name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" required></textarea>
|
||||||
<?php break; ?>
|
<?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
|
<?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 ) ) :
|
if ( is_array( $choices ) && ! empty( $choices ) ) :
|
||||||
foreach ( $choices as $choice_index => $choice_text ) :
|
foreach ( $choices as $choice_index => $choice_text ) :
|
||||||
$choice_value = esc_attr( $choice_text ); // Use text as value for simplicity
|
$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 endif; ?>
|
||||||
<?php break; ?>
|
<?php break; ?>
|
||||||
|
|
||||||
<?php case 'true-false': ?>
|
<?php case 'checkbox': // Added for metabox 'Checkboxes (Multiple Answers)' ?>
|
||||||
<label><input type="radio" name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" value="true" required> True</label><br>
|
<?php
|
||||||
<label><input type="radio" name="assessment_answer[<?php echo esc_attr( $question_id ); ?>]" value="false"> False</label>
|
$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 break; ?>
|
||||||
|
|
||||||
<?php default: ?>
|
<?php case 'numeric': // Added for metabox 'Numeric' ?>
|
||||||
<p class="error"><?php esc_html_e( 'Unsupported question type.', 'quiztech' ); ?></p>
|
<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; ?>
|
<?php endswitch; ?>
|
||||||
</div> <?php // .question-answer-area ?>
|
</div> <?php // .question-answer-area ?>
|
||||||
</div> <?php // .quiztech-question-container ?>
|
</div> <?php // .quiztech-question-container ?>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue