Learn how to create a multi-page form with php _ PHP Tutorial

Source: Internet
Author: User
Learn how to create multi-page forms with php. Of course, this is not the end. After all, if you can create multiple forms on a page, why cannot't you create a form across multiple pages? Unfortunately, the number of transfers from a page via HTTP is not over yet. After all, if you can create multiple forms on a page, why cannot't you create a form across multiple pages? Unfortunately, it is not easy to transfer data from one page to another through HTTP. Because there is no built-in mechanism in the HTTP protocol to define the concept of a series of pages. However, with some clever skills and some useful functions of PHP, we don't have to spend too much effort to break through this restriction. In this chapter, the key idea is to store the input obtained from the previous page to the hidden variable of the next page form. When we switch between different pages on the screen, the code also transmits information between pages, each form contains the data of the previous form. This method seems a bit clumsy, but it is currently the easiest method-and does not require the use of databases or cookies. It is expected that we will extend the use of the variable $ state to adapt to this feature. That's why we learned about this technique in the past and didn't intend to process multiple forms on a single page in a simpler way. For convenience, we will repeat the previous form example. However, this time we split it into two pages, rather than placing the important questions about cheese on the same page as the user name. In this way, we can get three functions instead of two. In addition, the function is slightly renamed to reflect changes in its content. Display_form () is now renamed display_name (). The function is the same as the previously introduced function, but we solve the next problem first, and change the name of the next stage to cheese to show you more clearly what to do next. The following is display_cheese (). The above code should look very familiar. Except for the $ name variable name and value in the previous part of the data before the hidden stage element is output, we did not make any unexpected changes. Instead of directly outputting the variable value, we use a PHP function named htmlspecialchars. In HTM, the following four characters should not be used in other places except as markup: "<", ">", "", and "&". Therefore, to ensure that the browser is not confused, we use the $ name variable through the htmlspecialchars () function. Therefore, a person whose name is "Bret & Jeff" will become "Brett & Jeff. Now, no information is missing when you submit this new form. The role of the above technique is that we do not 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 logic displayed on the page. Have you seen it? We only need to add elseif in the previous two statements. This is the clever use of the variable $ stage. If you want to add more pages, you only need to write a new function to display the desired content, and add a line of code to control it when it is displayed.

Bytes. After all, if you can create multiple forms on a page, why cannot't you create a form across multiple pages? Unfortunately, the number of messages sent from a page via HTTP...

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.