0

ページネーションのあるフォームページが 1 つあります。ページネーションを使用して、ユーザーが前または次のページに移動するときにフォームの値を保持したい。セッションスコープを使用して実行できることを知っています。ただし、ここではセッション スコープを使用したくありません。セッションを使用せずにこれを行う方法について誰かアイデアがありますか? 私にお知らせください。

ここに私のフォームページがあります:

<cfoutput>          
    <form action="#buildUrl(action='survey.save_surveyresults',querystring='surveyId=#rc.surveyid#')#"  method="post">
        <input type="hidden" name="id" value="0">
        <input type="hidden" name="surveyid" value="#rc.surveyId#">
             <div class="container-fluid">
                <div class="row">

                <div class="control-group">
                     <label class="label-control" for="name">Name</label>
                     <div class="controls">
                          <input type="text" name="name" id="name" required="true" placeholder="enter your name" value="#rc.name#">
                     </div>
                </div>

                <div class="control-group">
                     <label class="label-control" for="email">Email</label>
                     <div class="controls">
                          <input type="text" name="email" id="email" required="true" placeholder="enter your Email" value="#rc.email#">
                     </div>
                </div>

                           <cfloop query="rc.questions" startrow="#startrow#" maxrows="#perpage#">

                                  <!--- because we have all questions and answers in query we can use switch instead calling template or view
                                    for each question, so its simplify directory structures, questions directory is not necessary now --->

                                  <h3>#CurrentRow#<cfif rc.questions.isrequired><strong>*</strong></cfif>. #rc.questions.question#<h3> 
                                    <cfswitch expression="#rc.questions.template#">
                                    <fieldset> 

                                        <cfcase value="textbox">
                                            <input type="text" class="input-xlarge" name="#template#_#questionid#" id="question_#questionid#">
                                        </cfcase>


                                        <cfcase value="multiplechoice">
                                            <cfloop list="#answer#" delimiters="," index="i">
                                            <div class="controls">
                                                <label>
                                                   <input type="radio" name="#template#_#questionid#"  id="question_#questionid#" value="#answerID#" >
                                                   <span class="lbl">#i#</span>
                                                </label>
                                            </div>
                                            </cfloop>
                                        </cfcase>

                                        <cfcase value="multiplechoiceother">
                                            <cfloop list="#answer#" delimiters="," index="i">
                                            <div class="controls">
                                                <label>
                                                   <input type="radio" name="#template#_#questionid#"  id="question_#questionid#" value="#answerID#" >
                                                   <span class="lbl">#i#</span>
                                                </label>
                                            </div>
                                            </cfloop>
                                            <div class="control-group">
                                                   <label class="label-control" for="other">Other</label>
                                                   <div class="controls">
                                                      <input type="text" class="input-xlarge" name="#template#_#questionid#"  id="question_#questionid#">
                                                   </div>
                                             </div>
                                        </cfcase>



                                    </fieldset>     
                                    </cfswitch>         
                             </cfloop> 
                            <p></p><br />
                            <cfif startrow GT 1>
                                  <a href="#buildUrl(action='survey.survey_question',querystring='surveyid=#rc.surveyid#&startrow=#startrow-perpage#')#" class="btn">Previous</a>
                            </cfif>
                            <cfif (startrow + perpage - 1) lt rc.questions.recordcount>
                                  <a href="#buildUrl(action='survey.survey_question',querystring='surveyid=#rc.surveyid#&startrow=#startrow + perpage#')#" class="btn">Next</a>
                            <cfelse>
                                  <button type="submit" name="submit" class="btn btn-success">Finish</button> 
                            </cfif>
                      </div>  
                 </div>
             </div>
     </form> 
</cfoutput>
4

4 に答える 4

1

上記のアプローチでは、フォーム値を送信するたびに (または少なくとも最終処理の前に) サーバー側でフォーム値を再検証する必要があることに注意してください。

サーバーメモリで補うものは、規模によってはトラフィックとロード時間の点で失われる可能性があるため、慎重に進めることをお勧めします. 実稼働トラフィックを不必要に増加させると、財務上の影響が生じる可能性があり、多くの場合、サーバー メモリは、拡張されたトラフィックの支出よりも安くなる可能性があります。最終的には、お客様の要件と規模に依存します。

フォーム変数を配布すると、フォーム データの悪意のあるインジェクションに対する攻撃対象領域が増加します。そのため、セッション変数が変更されることに関心があるかもしれませんが (これについて詳しく知りたいと思います)、このデータをプレーンテキスト。この (または任意の) データについて、クライアント側の検証に依存しないでください。

于 2013-09-05T23:48:49.680 に答える
1

ダンが言ったように-送信された値を隠しフィールドに保存します。

あなたの HTML で見られる問題の 1 つは、前/次のページが単なるリンクであり、送信ボタンではないことです。そのため、これらのリンクをクリックするときに、ユーザーが別の URL に移動するだけでなく、フォームを送信していることを確認してください。

于 2013-09-05T12:23:07.980 に答える
1

すべてのフォーム変数を隠しフィールドに埋め込む簡単なコード スニペットを次に示します。このコードは、送信先のページのフォーム ハンドラー内に配置します。ルーカスの答えにも注意してください。不適切なフォームが原因で、フォームが正しく送信されていない可能性があります..er...フォーム。

<Cfloop collection="#form#" item="fItem">
<cfoutput>
<input type="hidden" name="#fItem#" value="#form[fItem]#"/>
</cfoutput>
</cfloop>

繰り返しになりますが、これは次のページのフォームの _inside になります。これは、マルチパート フォーム (複数のステップを持つショッピング カート、プロファイル エントリなど) ではかなり一般的です。

于 2013-09-05T13:38:00.610 に答える