Creation of course, it's not over here. After all, if you can create multiple forms on a single page, why can't you build a form across multiple pages?
Unfortunately, it's not easy to send data from one page to another page with 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 techniques and some useful functions of PHP, we can break through this limitation without too much effort. In this section, the key idea is to save the input from the previous page to the implied variable in the next page form. When we switch between different pages of the screen, the code also passes information between the pages, and each form contains the data from the previous form. This approach seems a bit clumsy, but it's the easiest way to do it right now-without using a database 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 don't intend to work with multiple forms in a single page in a simpler way.
For convenience, we'll use the previous form paradigm again and again. But this time we split it down into two pages, rather than putting the important issue of cheese on the same page as the user name.
This will result in three functions rather than two. In addition, the function is slightly renamed to reflect changes in its content. Display_form () has now been renamed Display_name ().
This is the same as the function described earlier, but let's fix the next question and change the name of the next stage to cheese to more specifically tell the user what to do next.
The code above should look very familiar. We did not make any unexpected changes except to output the $NAME variable name and value in the previous part of the data before outputting the hidden stage element. Instead of outputting the variable value directly, we pass a PHP function named Htmlspecialchars (). In HTM, the following four characters are used except as tokens (markup) and should not be used elsewhere: "<", ">", "" ", and" & ". Therefore, to ensure that browsers do not cause confusion, we use the $name variable with the Htmlspecialchars () function. As a result, someone's name "Bret & Jeff" will become "Brett & Jeff".
Now, when this new form is submitted, no information will be lost.
The trick is that we don't have to change any part of the original Process_form () function. In fact, we also keep the function name unchanged. Just add a new line to the page display logic.
Did you see it? We only need to add ElseIf to the previous two statements. This is the ingenious use of variable $stage. If we're going to add a few more pages, just write a new function to show what we want, and then add a line of code to control it when it's displayed.
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.