读书人

怎么用ASP判断表单为空的

发布时间: 2012-02-16 21:30:36 作者: rapoo

如何用ASP判断表单为空的?
<form id= "form1 " name= "form1 " method= "post " action= "check.asp ">
<p align= "center "> 网站名称:
<input name= "sitename " type= "text " id= "sitename " />
</p>
<p align= "center "> 网站地址:
<input name= "url " type= "text " id= "url " />
</p>
<p align= "center "> 联 系 人:
<input name= "lxr " type= "text " id= "lxr " />
</p>
<p align= "center "> 联系电话:
<input name= "tel " type= "text " id= "tel " />
</p>
<p align= "center "> 联系地址:
<input name= "add " type= "text " id= "add " />
</p>
<p align= "center "> 传    真:
<input name= "fax " type= "text " id= "fax " />
</p>
<p align= "center "> 邮    箱:
<input name= "mail " type= "text " id= "mail " />
</p>
<p align= "center ">
<input type= "submit " name= "Submit " value= "提交 " class= "anniu " />
     
<input type= "reset " name= "Submit2 " value= "重置 " class= "anniu "/>
</p>
</form>


请问这个表单该如何用ASP判断
如果不是空的话就去执行一条SQL语句

我看别的源代码里好像是这样写的 if action <> " " then
这样对不对?为什么要这样写?


[解决办法]
<%
sub textse(msg,text)
if request.form(text)= " " then
response.write " <Script> window.alert( ' "& msg & "不能为空 ');location.replace( '当前页面.asp '); </Script> "
response.end
end sub
%>
<%
if request( "action ")= "save " then
%>
<%call textse( "网站名称 ", "sitename ")%>
<%call textse( "网站地址 ", "url ")%>
<%call textse( "联系人 ", "lxr ")%>
<%call textse( "联系电话 ", "tel ")%>
<%call textse( "联系地址 ", "add ")%>
<%call textse( "传真 ", "fax ")%>
<%call textse( "邮箱 ", "mail ")%>
<%
sql= "..................... "
....执行SQL
end if
%>

再就是用JS去做判断,你指定要ASP就写ASP了~
------解决方案--------------------


可以,但是不密,可移植性不好
建使用Request.form( "表的元名 ")取得表面元的值
[解决办法]
<%
sub textse(msg,text)
if Trim(request.form(text))= " " then
response.write " <Script> window.alert( ' "& msg & "不能为空 ');location.replace( '当前页面.asp '); </Script> "
response.end
end sub
%>

可能楼主是想做2重判断,以防止别人从其他方式绕过前台判断
[解决办法]
恩,3楼说的不错,在1楼的基础上在修改下
<%
sub textse(msg,text)
if Trim(text)= " " then
response.write " <Script> window.alert( ' "& msg & "不能为空\n ');location.replace( '当前页面.asp '); </Script> "
response.end
end sub
%>

对需要判断的内容写以下代码,这样的function可以判断form来的或者其他方式来的。
<%textse(msg,Request.form( "表的元名 "))%>

读书人网 >ASP

热点推荐