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 ade979de5fc0e1ca0540f360a64c230b
#include "cgic.h"
#include bbed3fed50f96ac7490cfc6a498c4bc5
#include < ;stdlib.h>
char text_value[]={"AAAAAAAAA"}; // text_value is from a file
void htmlPage()
{
fprintf(cgiOut, "07e6e06e0dc95dc83bb70d14dca11cbe93f0f5c25f18dab9d176bd4f6de5d30en");
fprintf(cgiOut, "b2386ffb911b14667cb8f0f91ea547a7Test Form6e916e0f7d1e588d4f442bf645aedb2f9c3bca370b5104690d9ef395f2c5f8d1n");
fprintf(cgiOut, "1d6e7d87652dd104f173dbf7284e2799 n");
fprintf(cgiOut, "c2f918463c116861565ed8ab2faefec7n");
fprintf(cgiOut, "d0a0bbae8b180662e4a36083e4915683n",text_value);
fprintf(cgiOut, "5d08e27519ca030e56b2351ab84a98a1n");
fprintf(cgiOut, "2134320d759660fb73b514dbdadae69cn");
fprintf(cgiOut, "f5a47148e367a6035fd7a2faa965022en");
fprintf(cgiOut, "36cc49f0c466276486e50c850b7e4956n");
fprintf(cgiOut, "73a6ac4ed44ffec12cee46588e518a5en") ;
}
show_data.c:
#include ade979de5fc0e1ca0540f360a64c230b
#include "cgic.h"
#include bbed3fed50f96ac7490cfc6a498c4bc5
#include 8e359799bdf1a571032ba13cc96acda9
#include f55648144b4a1c5cce7ad2f6519be0f3
#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"];};
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"];};
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?