Это связан с моим предыдущим вопросом here, но я думаю, что это более простой.Показать Флажок выбора на странице сводки
Я создаю шаг за шагом процесс, который имеет несколько этапов, последний шаг будучи резюме страницы. На каждом шаге есть некоторые флажки, на итоговой странице я хочу показать, что было выбрано, и позволить им отправить форму.
я борюсь с пониманием процесса от связанного с этим вопроса, мы надеемся, это упрощенная версия поможет мне понять.
Вот мои настройки:
<?php $counter = 1;
$amount = get_field('select_number_of_questions');
$repeater = get_field("step_by_step_test");
shuffle($repeater);
$repeater_limit = array_slice($repeater,0,$amount);
foreach($repeater_limit as $repeater_row) { ?>
<div class="form-row">
<div id="modules-repeat">
<p class="training"><?php echo $repeater_row['question']; ?></p><br />
<p class="training-highlight">Please choose <span class="bold"><?php echo $repeater_row['required_answers']; ?></span> of the following answers:</p><br />
<?php $rows = $repeater_row['answer_options'];
foreach ($rows as $row){ ?>
<?php $Question[$counter] = $_POST['answer'.$counter]; ?>
<div style="display:table-row;">
<div style="display:table-cell;">
<input style="width: 20px;" type="checkbox" name="answer<?php echo $counter; ?>[]" value="<?php echo the_sub_field('answer'); ?>" />
</div>
<div style="display:table-cell;">
<p>
<?php echo $row['answer']; ?>
</p>
</div>
</div>
<?php } ?>
<div class="inner"></div>
<button class="next"></button>
<div class="clear"></div>
</div>
</div>
<?php $counter++; } ?>
<div class="form-row" id="form-row-last" style="display:none;">
<div id="modules-repeat">
<p>Summary page</p>
<?php foreach($repeater_limit as $repeater_row) { ?>
<p class="training"><?php echo $repeater_row['question']; ?></p><br />
<?php } ?>
<div class="inner"></div>
<button class="next"></button>
<div class="clear"></div>
</div>
</div>
Вот JQuery:
<script type="text/javascript">
jQuery(function($) {
$(document).ready(function() {
// prepend a 'previous' button to all form-rows except the first
$('<button>').addClass('previous').appendTo($('.inner').not(':first'));
// hide all form-rows, but not the first one
$('.form-row').not(':first').hide();
// hide on last step
$('button.next').last().hide();
// add the submit button to the last form-row
$('<input>').addClass('check').prop('type', 'submit').appendTo($('.form-row:last'));
// handle the previous button, we need to use 'on' here as the
// previous buttons don't exist in the dom at page load
$('.form-row').on('click', 'button.previous', function(e) {
e.preventDefault();
$(this).parents('div.form-row').hide().prev('div.form-row').show();
});
$('button.next').click(function(e) {
// prevent the next buttons from submitting the form
e.preventDefault();
// hide this form-row, and show the next one
$(this).parents('div.form-row').hide().next('div.form-row').show();
});
});
});
</script>
@Niels в настоящее время имеет самый близкий ответ. Это моя настройка html/php, с использованием jquery из ответа @Niels, она захватывает вопрос, но не тот, который проверен.
<p class="training"><?php echo $repeater_row['question']; ?></p><br />
<p class="training-highlight">Please choose <span class="bold"><?php echo $repeater_row['required_answers']; ?></span> of the following answers:</p><br />
<div class="question" data-max-answers="<?php echo $repeater_row['required_answers']; ?>">
<?php $rows = $repeater_row['answer_options'];
foreach ($rows as $row){ ?>
<?php $Question[$counter] = $_POST['answer'.$counter]; ?>
<div style="display:table-row;">
<div style="display:table-cell;">
<input style="width: 20px;" type="checkbox" name="answer<?php echo $counter; ?>[]" value="<?php echo the_sub_field('answer'); ?>" />
</div>
<div style="display:table-cell;">
<p>
<?php echo $row['answer']; ?>
</p>
</div>
</div>
<?php } ?>
</div>
<div class="inner"></div>
<button class="next"></button>
<div class="clear"></div>
</div>
В чем вопрос? Что вы пробовали? – Misch
То же самое: в чем проблема? Просто сохраните все данные на СЕССИИ, а в конце (последнем шаге) всех шагов просто проверьте, все ли отправлено. Проверено успешно, покажите резюме. – djot