How to retain the entered information after a PHP form submission failure _ PHP Tutorial

Source: Internet
Author: User
Tags php form
How to retain the entered information after PHP fails to submit the form. This article introduces some methods to summarize how to retain the entered information after PHP fails to submit the form. The most common method is to use the cache method, this method is possible if the network speed is slow. This article will introduce some methods to summarize how to retain the entered information after PHP fails to submit the form. The most common method is to use the cache method, if the network speed is slow, the best way is to use ajax.

1. use the header to set the Cache control header Cache-control.

PHP code
1.

The code is as follows:
Header ('cache-control: private, must-revalidate'); // supports page jump back

2. use the session_cache_limiter method.

PHP code

The code is as follows:
1. session_cache_limiter ('private, must-revalidate'); // before session_start

The following describes the parameters of session_cache_limiter:

The meanings of several parameters in session_cache_limiter are as follows:
Nocache: of course, it is not cached (for example, the form information is cleared), but public variables can be cached.
Private: private cache (for example, the form information is retained but valid during the lifetime)
Private_no_cache: Private mode but not expired (form information is retained)
Publice: public (the form information is also retained)

Set the cache Expiration Time: Set the session_cache_expire function. the default value is 180 minutes.

Frequently encountered problems:

1. Session_cache_limiter ("private"); the form information is retained. However, if I modify the submitted information, the information displayed on the form page is still in the cache and cannot be automatically refreshed in time, if session_cache_limiter ("private") is not used, the form information cannot be retained.

Solution:

Before session_start, add

The code is as follows:

Session_cache_limiter ("private, must-revalidate ");


Another way is to use ajax for instances.


Large content of the index.html template file:

The code is as follows:



JQuery Ajax instance demo

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.