5

私は自分の道をナビゲートできないように見える問題を抱えています。

まず、専門家によって作成されたウェブサイトを持っていますが、その会社とは仕事上の関係がありません。現在、私は自分でサイトを管理しています。私は有能ですが、経験豊富な Web 開発者ではありません。

背景: エンドユーザーに提示される複数ページのフォームを使用する申請手続きがあります。フォームは 7 つのステップで表示されますが、すべて 1 つの php ファイルから実行されます。jquery / javascript を使用してステップを循環し、いくつかのフィールドを検証します。最後のステップでは、ユーザーが送信する要約が表示されます。これは美しく機能します。

以下は、ページの循環を処理する関連する JavaScript であると私が信じているものです。

<script>
$(function () {

    window.confirmLeave = true;

    $('.datefield').datepicker();

    var cache = {};                                                                                             // caching inputs for the visited steps

    $("#appForm").bind("step_shown", function(event,data){  

         if(data.isLastStep){                                                                                      // if this is the last step...then
                $("#summaryContainer").empty();                                                                     // empty the container holding the 
                $.each(data.activatedSteps, function(i, id){                                                        // for each of the activated steps...do
                    if(id === "summary") return;                                                                    // if it is the summary page then just return
                    cache[id] = $("#" + id).find(".input");                                                         // else, find the div:s with class="input" and cache them with a key equal to the current step id
                    cache[id].detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled");  // detach the cached inputs and append them to the summary container, also show and enable them
                });
            }else if(data.previousStep === "summary"){                                                              // if we are movin back from the summary page
                $.each(cache, function(id, inputs){                                                                 // for each of the keys in the cache...do
                    var i = inputs.detach().appendTo("#" + id).find(":input");                                      // put the input divs back into their normal step
                    if(id === data.currentStep){                                                                    // (we are moving back from the summary page so...) if enable inputs on the current step
                         i.removeAttr("disabled");
                    }else{                                                                                          // disable the inputs on the rest of the steps
                        i.attr("disabled","disabled");
                    }
                });
                cache = {};                                                                                         // empty the cache again
            }
        });

</script>

以下のフォームのhtmlも含めました。

<form name="appForm" id="appForm" action="submit-app-exec.php" method="post" 
enctype="multipart/form-data" autocomplete="off" onSubmit="showProgressBar()">

<fieldset class="step" id="page_1">
<div class="input">
<?php include("add-company/step1.html"); ?>
</div>
</fieldset>

<fieldset class="step" id="page_2">
<div class="input">
<?php include("add-company/step2.html"); ?>
</div>
</fieldset>

<fieldset class="step" id="page_3">
<div class="input">
<?php include("add-company/step3.html"); ?>
</div>
</fieldset>

<fieldset class="step" id="page_4">
<div class="input">
<?php include("add-company/step4.html"); ?>
</div>
</fieldset>    

<fieldset class="step" id="page_5">
<div class="input">
<?php include("add-company/step5.html"); ?>
</div>
</fieldset>

<fieldset class="step" id="page_6">
<div class="input">
<?php include("add-company/step6.html"); ?>
</div>
</fieldset>

<fieldset class="step" id="page_7">
<div class="input">
<?php include("add-company/step7.html"); ?>
</div>
</fieldset>

<fieldset class="step" id="summary" >
    <span class="font_normal_07em_black">Summary page</span><br />
    <p>Please verify your information below.</p>
    <div id="summaryContainer"></div>
</fieldset>

<div id="wizardNavigation">

    <button class="navigation_button" onclick="javascript:saveApp()">Save</button>
    <input class="navigation_button" id="back" value="Back" type="reset" />
    <input class="navigation_button" id="next" value="Next" type="submit" onclick="javascript:noSaveApp()" />

    <div class="clearFix"></div>
</div>

ページが読み込まれると、各フィールド セットには追加のクラスおよびスタイル属性があります。

class="step ui-formwizard-content ui-helper-reset ui-corner-all" style="display: none;"

プロセス中、firebug で見ることができ、display: none; が表示されることを確認できます。そのフィールドセットと対話するとき、循環して「ブロック」に変わります。

問題: ユーザーが進行状況を保存して後で完了するための方法は一切構築していません。私は今これをやろうとしています。「保存」ボタンを正常に作成しました。これにより、フォームのアクションを変更する JavaScript がトリガーされ、POST データを処理して MySQL に処理する新しい php ファイルにデータが投稿されます。これは機能しますが、POST はすべてのデータを POST するのではなく、現在表示されているフィールドセットからのデータのみを渡します。そして、すべてのフォーム データが POST されていることを確認する方法がわかりません。ガイダンスや提案は役に立ちます。ありがとう。

編集:

次のようにして、正しいページを読み込むことができました。

$(function(){ $('#appForm').formwizard('show','" . $row["current_step"] . "'); }); 

これにより、正しいページが読み込まれます。ここでの問題は、これの最後のステップが、最終提出のためのすべての入力要素を示す要約ページであることです。ただし、表示されたページの要素のみが表示されるようです。最終的な要約で要素が表示されるかどうかを決定するのは、配列「data.activatedSteps」であると確信しています。あなたのコードは私のものよりもこれにうまく対処できますか? このたびはご協力いただきありがとうございました。–</p>

4

1 に答える 1

6

<input>プロパティを持つオブジェクトは'disable'、post/get では返されません。

これは、質問で注意を払うことが重要な JavaScript です。

if(id === data.currentStep){                                                                    // (we are moving back from the summary page so...) if enable inputs on the current step
    i.removeAttr("disabled");
}else{                                                                                          // disable the inputs on the rest of the steps
    i.attr("disabled","disabled");
}

これは、前のコーダーがユーザーが編集できるものを制御する方法です。ユーザーが最初に保存ボタンを押したときにすべての値を送り返したい場合

removeAttr("disabled");

ページ上のすべてのものから投稿/取得を送信します。

以前のコーダーは、ページ上のすべてのデータを調べて、ここで無効にしないことでこれを達成したようです。

if(data.isLastStep){                                                                                    // if this is the last step...then
    $("#summaryContainer").empty();                                                                     // empty the container holding the 
    $.each(data.activatedSteps, function(i, id){                                                        // for each of the activated steps...do
        if(id === "summary") return;                                                                    // if it is the summary page then just return
        cache[id] = $("#" + id).find(".input");                                                         // else, find the div:s with class="input" and cache them with a key equal to the current step id
        cache[id].detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled");  // detach the cached inputs and append them to the summary container, also show and enable them
    });
}

したがって、返品を投稿するときにそのコードを呼び出すか、そのようなことを行ってページの入力を有効にすることができます。

編集:

あなたのコメントから、これを使用して問題を解決し、ページ上のオブジェクトを同じユーティリティとライブラリで一貫して操作することをお勧めします。さらに、JQuery は非常に便利です。

$(':input.ui-wizard-content').each(function() {$( this ).removeAttr("disabled");});

:inputページ上のすべての入力を取得します。.ui-wizard-contentそのクラスの入力のみを探すように JQuery に指示し、見つかったオブジェクトで.eachラムダ関数 ( function() {$( this ).removeAttr("disabled");}) を実行する各オブジェクトをループします。

編集2:

コードに何が入っているかを伝えるのは困難$row[]です。それは明らかにコンテナですが、あなたが与えたコードは文脈から少し外れているので、それが何であるかはわかりません.

そうは言っても、操作するDOM(ページ上の内容のJavaスクリプト表現)しかなく、以前に投稿した関数について知っている場合、私はこのようなことをします。

交換

if(data.isLastStep){                                                                                    // if this is the last step...then
    $("#summaryContainer").empty();                                                                     // empty the container holding the 
    $.each(data.activatedSteps, function(i, id){                                                        // for each of the activated steps...do
        if(id === "summary") return;                                                                    // if it is the summary page then just return
        cache[id] = $("#" + id).find(".input");                                                         // else, find the div:s with class="input" and cache them with a key equal to the current step id
        cache[id].detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled");  // detach the cached inputs and append them to the summary container, also show and enable them
    });
}

if(data.isLastStep){ 
    $("#summaryContainer").empty();
    $('.input :input').detach().appendTo('#summaryContainer').show().find(":input").removeAttr("disabled");
}

これは、以前のコーダーが行っていたことからほとんど借りています。data.activatedSteps彼は、自分が作成したワークフローのおかげで、フォーム内のすべてが含まれていると思っていましたが、そうではありませんでした。したがって、彼がデータを追加する場所を確認しdata.activatedSteps、リロード時に保存されたものを同じ方法でそこに置く必要があります。または、そのすべてを無視し、オブジェクト内のすべてをクラスでdata取得してコンテナに追加する私の行を使用するだけです。<input>input

注: JQuery$(TEXT)は、CSS と同じオブジェクト定義構文を使用し、':input' などの特別に使いやすいアドインを使用します。私がここで話していることについては、CSS リファレンスと JQuery の特別なセレクター構文のチェックについての優れたリファレンスがここにあります。これが、非常にコンパクトなステートメントで、あなたが興味を持っているものすべてをつかむものを書く方法を私が知っている方法です.

于 2013-10-14T17:50:11.860 に答える