Learn how to create a multi-page form _php tutorial with PHP

Source: Internet
Author: User
Of course, this is not the end. After all, if you can build multiple forms on a single page, why can't I create a form that spans multiple pages? Unfortunately, it's not easy to use HTTP to transfer data from one page to another. Because there is no built-in mechanism in the HTTP protocol to define the concept of a series of pages. However, with only a few clever tricks and some useful PHP functions, we can break this limit without too much effort. In this chapter, the key idea is to store the input from the previous page in an implied variable in the next page form. When we switch between pages on a screen, the code also passes information between pages, each containing data from the previous form. This approach seems a bit awkward, but it's the easiest way to do it--without using databases or cookies. It is expected that we will extend the use of variable $state to accommodate this feature. That's why we've learned about this technique in the past, and we're not going to use more simple ways to work with multiple forms in a single page. For the sake of convenience, we will reuse the previous form paradigm. But this time we'll split it into two pages, rather than putting the important questions about cheese on the same page as the user name. This results in three functions instead of two. In addition, the function is slightly renamed to reflect changes in its content. Display_form () has now been renamed Display_name (). The same function as previously described, but let's fix the next problem and change the name of the next stage to cheese to make it clearer what the user is going to do next. Next is Display_cheese (). The above code should look familiar. We did not make any unexpected changes except to output the $name variable names and values in the previous part of the data before outputting the hidden stage element. Instead of outputting the variable value directly, we passed a PHP function called Htmlspecialchars (). In the HTM, there are four characters in addition to being used as tags (markup), which should not be used elsewhere: "<", ">", "" ", and" & ". Therefore, to ensure that the browser does not cause confusion, we use the $name variable through the Htmlspecialchars () function. As a result, a person whose name is "Bret & Jeff" will become "Brett & Jeff". Now, when this new form is submitted, no information is lost. The trick is that we don't have to change any part of the original Process_form () function. In fact, we will keep the function name unchanged. You only need to add a new line to the page display logic. Did you see it? We only need to add ElseIf to the previous two declarations. This is precisely the clever place to use variable $stage. If we're going to add a few more pages, just write a new function to show what you want, and add a line of code to control it when it's displayed.

http://www.bkjia.com/PHPjc/531901.html www.bkjia.com true http://www.bkjia.com/PHPjc/531901.html techarticle Of course, this is not the end. After all, if you can build multiple forms on a single page, why can't I create a form that spans multiple pages? Unfortunately, using HTTP to transfer numbers from one page ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.