4

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

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.

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

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

user1830984
  • 859
  • 3
  • 14
  • 26
  • 1
    Is this, by chance, a class assignment? [This guy](http://stackoverflow.com/questions/14189739/how-to-unlock-the-correct-page) is asking very similar questions. Perhaps you should collaborate. – user229044 Jan 07 '13 at 04:09
  • @meagar I can see he is trying to lock out pages. Hmmm... Maybe that could work. This is an assignment in university undergraduate but I doubt that person is doing same as what I am doing. For starters mine only deals with three pages, he has 6 pages – user1830984 Jan 07 '13 at 04:14
  • Unfortunately nobody will provide you "sample codes" for this, because what you're asking for is an entire web app. I will describe the rough logic your pages will need though, and if you find yourself stuck on some specific part you should ask another question. – user229044 Jan 07 '13 at 04:18

1 Answers1

0

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.

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

    Do I have answers for page 1 questions?
      No: Render page 1 questions
      Yes: Redirect to page 2
    
  • 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

    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.

user229044
  • 232,980
  • 40
  • 330
  • 338