不希望页面跳过或返回 [英] Don't want page skipping ahead or going back

查看:60
本文介绍了不希望页面跳过或返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览器上创建一个应用程序,但我不希望用户在浏览器的某些页面上跳过页面。想一想。如果我希望用户创建一些东西,但是为了让他们能够创建一些东西,他们必须经过第1,2和3页,如果用户在第1页但是然后通过输入url设法跳到第3页会发生什么?它有点混乱

I am creating an application on the browser but I do not want the user to skip pages while on certain pages in my browser. Think of this. If I want user to create something but for them to be able to create something they must go through pages 1, 2 and 3, well what happens if user is on page 1 but then manage to skip to page 3 by entering url? It kinds of messes it up

再次处理第1,2,3页,如果用户完成第1页,数据插入数据库,但是如果用户在第2页那么我不希望他们回到第2页,因为我不希望他们改变以前输入的任何细节。我不希望用户在使用转发浏览器按钮时做类似的事情。

Again dealing with page 1,2,3, if user completes page 1, data inserted in database, but then if user is on page 2 then I don't want them to go back to page 2 because I don't want them to change any details the previously entered. I don't want user to do similar thing when using forward browser button.

我需要在所有主流浏览器中工作,IE,Chrome,Firefox,Firefox,Opera

I need this working in all major browsers, IE, Chrome, Firefox, Firefox, Opera

示例代码对我非常非常有用。

A sample code will be very, very helpful to me.

推荐答案

您的表单将回复您服务器的答案。您的服务器必须验证这些答案。如果答案有效,则应将它们存储在数据库中。如果答案无效,您将需要重新呈现表单,可能填充了用户的输入,并显示某种错误,并重复此过程。

Your form will post back answers to your server. Your server must validate those answers. If the answers are valid, you should store them in the database. If the answers are invalid, you'll want to re-render the form, probably populated with the user's inputs, and display some kind of error, and repeat this process.

如果用户的答案有效,您将把它们写入数据库并将用户重定向到下一页。在下一个请求中,您可以使用第一页的答案的存在来确定是否应该访问第2页。如果没有,您需要将它们重定向到第一页。

If the user's answers are valid, you'll write them to the database and redirect the user to the next page. On this next request, you can use the existence of answers for the first page to determine whether page 2 should be accessible. If not, you need to redirect them to the first page.

每个页面中极其简化的逻辑将如下所示:

The extremely simplified logic within each page will look something like this:


  • page1.php

  • page1.php

Do I have answers for page 1 questions?
  No: Render page 1 questions
  Yes: Redirect to page 2


  • page2.php

  • page2.php

    Do I have answers for page 1 questions?
      No: redirect to page 1
      Yes:
        Do I have answers for page 2 questions?
          No: Render page 2 questions
          Yes: Redirect to page 3
    


  • page3.php

  • page3.php

    Do I have answers for page 1 questions?
      No: redirect to page 1
      Yes:
        Do I have answers for page 2 questions?
          No: Redirect to page 2
          Yes: 
            Do I have answers for page 3 questions?
              No: Render page 3 questions
              Yes: Render "you are finished" page
    


  • 或者更一般地说,每个页面应该找到没有答案的第一页,并且(如果那不是当前页面)重定向到该页面。

    Or more generally, each page should find the first page that doesn't have answers, and (if that's not the current page) redirect to that page.

    这篇关于不希望页面跳过或返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆