分类: Delphi
2011-05-22 12:53:26
实验二、提交按钮
我们在上一个实验的页面中增加两个按钮,一个为提交按钮,一个为重置按钮,用DW画在页面上,部分代码如下:
Hello To My CGIC Test!
:
提交" />
重置" />
修改mycgictest.c文件:
#include "cgic.h"
#define USER_NAME_MAX_BYTE 51
int hand_user_name(char *formname,char *username,int name_maxlength);
//处理用户名的函数
int cgiMain(){
char user_name_result[USER_NAME_MAX_BYTE-1];
int hand_result=-3;
cgiHeaderContentType("text/html");
fprintf(cgiOut,"\n");
fprintf(cgiOut,"
fprintf(cgiOut,"\n");
fprintf(cgiOut,"\n");
//HTML BODY
if(cgiFormSubmitClicked("name_submit")==cgiFormSuccess){
hand_result=hand_user_name("user_name",user_name_result,USER_NAME_MAX_BYTE);
}
switch(hand_result){
case -1:
fprintf(cgiOut,"OH! You have a mars name,it is too long!\n回火星去吧");
break;
case -2:
fprintf(cgiOut,"OH! You have not input you name!");
break;
case 0:
fprintf(cgiOut,"Whelcom ");
fprintf(cgiOut,user_name_result);
break;
default:
fprintf(cgiOut,"Do you have a name?");
break;
}
fprintf(cgiOut,"\n");
return 0;
}
int hand_user_name(char *formname,char *username,int name_maxlength){
int fetch_result=cgiFormStringNoNewlines(formname,username,name_maxlength);
if(fetch_result==cgiFormTruncated){
return -1;
}else if(fetch_result==cgiFormEmpty){
return -2;
}else if(fetch_result==cgiFormSuccess){
return 0;
}
return -3;
}
在这个实验中我们主要使用了cgiFormSubmitClicked()函数来检查用户所点击的提交按钮,并更加提交按钮的不同来做不同的处理。