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

Source: Internet
Author: User
Tags php form
This article mainly describes how to retain the information that has been filled in after PHP fails to submit a form. For more information, see this article, the most common method is to use the cache method. if the network speed is slow, it may cause problems. The best way is to use ajax.

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

The PHP code is as follows:

Header ('cache-control: private, must-revalidate'); // supports page jump back

2. use the session_cache_limiter method.

The PHP code is as follows:

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

session_cache_limiter( "private, must-revalidate" );

You can.

2. Another method is to use ajax for instances.

The content of the index.html template file 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.