Table of Contents
Solution to the problem of returned data disappearing after php form submission error, php form
Home Backend Development PHP Tutorial Solution to the problem of missing return data after php form submission error, php form_PHP tutorial

Solution to the problem of missing return data after php form submission error, php form_PHP tutorial

Jul 12, 2016 am 08:55 AM
php

Solution to the problem of returned data disappearing after php form submission error, php form

This article introduces to programmers the solution to the problem of returned data disappearing after php form submission error, Interested programmers can refer to it.

What should I do if the returned data disappears after the form is submitted incorrectly? Today we will analyze and solve this problem.

Condition Overview:

A problem encountered when filling in form information and submitting it is that after the user fills in and submits the form, the program determines that it does not meet the requirements and returns. After returning, the previously filled form information will be cleared. It doesn't matter if the amount of information filled in is small, but if the amount of information filled in is relatively large, it will directly affect the good mood of the person filling in the information. Therefore, solving the problem of the filled-in content disappearing after a form submission error returns is an urgent issue to improve user experience.

For this kind of problem, we have summarized the following situations:

(1) The page uses the session_start function. One feature of this function is that it will force the current page not to be refreshed. The solution is to add the following code after this function:

<span>header</span>("Cache-control:private");<span>//</span><span>注意在本行之前你的PHP程序不能有任何输出 </span>
Copy after login

There are several other solutions by adding

before session_start
<span>session_cache_limiter</span>('nocache'); <span>//</span><span>清空表单 </span>
<span>session_cache_limiter</span>('private'); <span>//</span><span>不清空表单,只在session生效期间 </span>
<span>session_cache_limiter</span>('public'); <span>//</span><span>不清空表单,如同没使用session一般 </span>
Copy after login

The above setting of session will cause the seesion to be cached, which will cause the problem that the session information cannot be updated when you apply it to the session. For this reason, this article proposes several other solutions below.

(2) Use the Header method to set the message header Cache-control and add the following code to the page:

<span>header</span>('Cache-control: private, must-revalidate');  <span>//</span><span>支持页面回跳,注意本行之前不能有任何输出</span>
Copy after login

(3) Use the session_cache_limiter method and add the following code to the page:

<span>session_cache_limiter</span>('private, must-revalidate'); <span>//</span><span>注意要写在session_start方法之前 </span>
Copy after login

The following is a supplementary explanation of the Cache-Control message header field:

Cache-Control specifies the caching mechanism that requests and responses follow. Setting Cache-Control in a request message or response message does not modify the caching process during the processing of another message. The caching instructions in the request include no-cache, no-store, max-age, max-stale, min-fresh, only-if-cached, and the instructions in the response message include public, private, no-cache, no-store, no-transform, must-revalidate, proxy-revalidate, max-age. The meaning of the instructions in each message is as follows:

Public: indicates that the response can be cached by any cache.

Private: Indicates that all or part of the response message for a single user cannot be processed by the shared cache. This allows the server to only describe a partial response from a user that is not valid for other users' requests.

no-cache: Indicates that the request or response message cannot be cached

no-store: Used to prevent important information from being released unintentionally. Sending it in the request message will cause both the request and response messages to use caching.

max-age: Indicates that the client can receive responses with a lifetime no greater than the specified time in seconds.

min-fresh: Indicates that the client can receive responses with a response time less than the current time plus the specified time.

max-stale: Indicates that the client can receive response messages beyond the timeout period. If you specify a value for max-stale messages, the client can receive response messages that exceed the specified value of the timeout period.

After reading this article, if you encounter similar problems, you will be able to completely solve them. Please remember that this solution is only for PHP websites.

Original address: http://www.manongjc.com/article/600.html

Related reading:

php implements receiving multiple form data instances with the same name but different values

php obtain form data example sharing

php A complete form validation example

Two ways to submit form in php

jQuery formValidator form validation

A simple form validation example with jquery

Several ways to prevent repeated submission of forms in php

Detailed explanation of usage of js form onsubmit event

jquery A complete non-refresh ajax submission form example

jquery uses ajax to submit the form

php uses curl to simulate post submission

php simulates form post submission through fsockopen

php form $_POST[] example application

Share a common JavaScript method to verify whether the form is empty

php form submitted to this page

Several ways to get form elements in javascript

javascript A complete form validation example

Use js to submit form

Example application of form form in php

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1115253.htmlTechArticleSolution to the problem of returned data disappearing after php form submission error, php form This article introduces php form to coders The solution to the problem of returning data disappearing after submitting an error. If you are interested...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles