Home > Web Front-end > HTML Tutorial > Submit to the current page, how to solve the problem of refreshing the repeated submission form? _html/css_WEB-ITnose

Submit to the current page, how to solve the problem of refreshing the repeated submission form? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:25:40
Original
1793 people have browsed it

This post was last edited by lljl2009 on 2013-12-09 19:59:49

I am a complete novice, please give me some advice!
The requirements are:
1. There is a form on the page and two buttons, one is save and the other is cancel; the data in the form is read from file a;
2. In the form After the content is modified, click save to save the data to file a, and the current page will still be displayed; click cancel to cancel the changes;
3. The problem is that the form will be submitted repeatedly when clicking refresh. I implemented it with cgi and wrote The simple code is as follows:
show.html:
#include
#include "cgic.h"
#include
#include < ;stdlib.h>

char text_value[]={"AAAAAAAAA"}; // text_value is from a file
void htmlPage()
{
fprintf(cgiOut, "< html>n");
fprintf(cgiOut, "Test Form
n");

fprintf(cgiOut, "< body> n");

fprintf(cgiOut, "
n");

fprintf(cgiOut, "n",text_value);

fprintf(cgiOut, "n");
fprintf(cgiOut, "n");
fprintf(cgiOut, "
n");

fprintf(cgiOut, "n");
fprintf(cgiOut, "n") ;
}

show_data.c:
#include
#include "cgic.h"
#include
#include
#include
#include "mypage.h"


int cgiMain()
{
if (cgiFormSubmitClicked("save") == cgiFormSuccess)
{
// save data to a file;
// ...
// reload page;
cgiHeaderContentType("text/ html");
htmlPage();
return 0;
}
//read data from a file
// ...
cgiHeaderContentType("text/html") ;
htmlPage();
return 0;
}


4. I tried several methods on the Internet: using global variables in javascript and using a hidden control are both No, because this value is always the initial value after my page is reloaded. It also doesn't work if I use a hidden iframe and then the form's target points to this frame. In this way, cancel can still be executed after clicking save; the save control cannot be disabled after submission. , because I still need to do some data saving and other processing in cgiMain, and this part is not executed after disable. . .

I don’t understand how other session, ajax and other methods are used. Can they achieve the purpose? Can you give me some advice on what to do? No clue. . .

Thank you!

Reply to the discussion (solution)

Generate a random timestamp at the back of the page
Compare the session before background extraction
For example:
http:/ /www.baidu.com?p=12345678912
Server-side fetch

if( isset( $_GET["p"] ) && $_GET["p"] != session["submit"] ){    // do sth.    // session["submit"] = $_GET["p"];};
Copy after login
Copy after login

Generate a random timestamp at the back of the page
Compare the session before background extraction
For example :
http://www.baidu.com?p=12345678912
Server-side fetch

if( isset( $_GET["p"] ) && $_GET["p"] != session["submit"] ){    // do sth.    // session["submit"] = $_GET["p"];};
Copy after login
Copy after login


Thank you for your reply! When does the back of the page mean? Where should I do this in this code? Also is there this Php code that I can apply directly to my code?

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template