1

これは私の前の質問に関連していますが、もっと簡単だと思います。

いくつかのステップからなるステップバイステップのプロセスを作成しています。最後のステップは要約ページです。各ステップにはいくつかのチェックボックスが含まれています。概要ページで、選択した内容を表示してから、フォームを送信できるようにします。

関連する質問からプロセスを理解するのに苦労しています。この簡略化されたバージョンが理解に役立つことを願っています。

これが私の設定です:

<?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セットアップであり、@ Niels回答からのjqueryを使用して、質問を取得しますが、チェックされる回答は取得しません。

<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>
4

4 に答える 4

3

ビジネスロジックとは何ですか?

*(ユーザーがフォームを送信する前に)ページ上の目的の入力フィールドのすべての値を取得します。次に例を示します。

var name = $('#name').val();
...
var city = $('#citySelectBox').val();

*目的を表示するために、要約セクションでこれらの変数を使用します。

*これらを確認した後、ユーザーはフォームを送信するか、すでに入力されているフィールドに変更を加えます。

于 2013-04-03T12:57:35.870 に答える
1

チェックボックスの変更を取得してから、選択肢が投稿されている場所にLIまたはブレークのリストを生成してみませんか?何かのようなもの:

$("input[type=checkbox]").on("change", function(){
    var html = "";
    // Get checked checkboxes
    $(".form-row").each(function(){
        var question = $(this).find(".training").text(),
            checkedlist = [];
        $(this).find("input:checked").each(function(){
            checkedlist.push($(this).val());
        });
        // Add question and answers to the summary, only if minimum of 1 checkbox checked
        if( checkedlist.length )
        {
            html += "Question: '" + question + "': " + checkedlist.join(", ") + "<br />";
        }
    });

    $(".inner").html(html);
});
于 2013-04-08T16:42:44.077 に答える
0

あなたはおそらくこのようなものが欲しいでしょう。難しくしすぎないでください:)

JSfiddle

JSfiddle(質問の例付き)

HTML

<div class="page1">1<br /><button>Next</button></div>
<div class="page2">2<br /><button>Next</button></div>
<div class="page3">3<br /><button>Next</button></div>
<div class="page4">4<br /><button>Next</button></div>
<div class="page5">5<br /><button>Next</button></div>
<div class="page6">6 (end)</div>

CSS

div[class^="page"] {
    display: none;
    margin: 20px auto;
    padding: 15px;
    width: 400px;
    height: 200px;
    box-sizing: border-box;
    background-color: orange;
    -moz-box-shadow:    3px 3px 5px 6px #ccc;
    -webkit-box-shadow: 3px 3px 5px 6px #ccc;
    box-shadow:         3px 3px 5px 6px #ccc;
}

JavaScript

$(document).ready(function() {
    $('.page1').css('display', 'block');

    $('div[class^="page"] button').click(function(evt) {
        evt.preventDefault();

        // Figure out the current page
        var page_nr = $(this).parent().attr('class');
        page_nr = page_nr.replace('page', '') * 1;

        // Hide current page
        $(this).parent().animate(
            { opacity: 'hide', display: 'none' },
            750, function() {
                // Show next page
                $('.page' + (page_nr + 1)).animate({ opacity: 'show', display: 'block' }, 750);
            });
    });
});

各ページのフォームの変数の保守を処理する方法についてのアドバイスも必要な場合は、詳細をコメントに残してください。回答を更新します。

クリックして次のページに移動すると、ページごとのデータを簡単に処理できます。一部のデータが無効な場合は、次のページを表示しないようにすることもできます。

幸運を!

于 2013-04-01T18:51:01.917 に答える
0

おそらく最も簡単/簡単/面倒な解決策は、最後のフォームページを「受け入れ」た後にすべてのページを表示することですが、透明なオーバーレイを介して行を無効にします(入力を無効にしないでください。これにより、送信で無効なフィールドが無視されます) 。

今のところ私はあなたのコードを手伝うことはできませんが、理論的にはこれがあなたが必要としているものです...

于 2013-04-08T18:11:01.113 に答える