Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test URL From ASP 1

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
In my ASP form I have a field for a URL. Is there any way I can test it in my validation routine before a user saves the record?

Can I trap for an error if an URL is bad etc?

Thanks!
 
Try this:

****** check.asp ****
'part 1: the post form
'*********************
<%
strFrom=request.form(&quot;result&quot;)
strResult=request.form(&quot;url&quot;)
%>
<HTML>
<HEAD>
<TITLE>URL check</TITLE>
</HEAD>
<BODY>
<FORM method=&quot;post&quot; action=&quot;checkurl.asp&quot;>
<P><INPUT type=&quot;text&quot; name=&quot;url&quot;></P>
<P><INPUT type=&quot;submit&quot; value=&quot;submit&quot; name=&quot;submit&quot;></P>
</FORM>
<P><%= strFrom %></P>
<P><%= strResult %></P>
</BODY>
</HTML>
'****** checkurl.asp ****
'part 2: the actual check
'************************
<%
strURL=request.form(&quot;url&quot;)
if strURL<>&quot;&quot; Then
if left(lcase(strURL),7)<>&quot; Then
strURL=&quot; & strURL
End if
On Error Resume Next
Dim objHTTP
Dim sHTML
Set objHTTP = Server.CreateObject (&quot;Microsoft.XMLHTTP&quot;)
objHTTP.open &quot;GET&quot;, strURL, False
objHTTP.send
sHTML=objHTTP.statusText
if err or sHTML<>&quot;OK&quot; Then
sTxt=&quot;fail&quot;
else
sTxt=&quot;ok&quot;
End if
Set objHTTP=nothing
else
sTxt=&quot;fail&quot;
End if
strFrom=request.ServerVariables(&quot;HTTP_REFERER&quot;)
p=instr(1,strFrom,&quot;?&quot;)
if p>0 Then
strFrom=left(strFrom,p-1)
End if
response.redirect &quot;checkdone.asp?result=&quot; & sTxt & &quot;&ref=&quot; & strURL & &quot;&return=&quot; & strFrom
%>
'****** checkdone.asp ****
'part 3: post the results back to the re
' ferer
'************************
<%
strRes=request.querystring(&quot;result&quot;)
strRef=request.querystring(&quot;ref&quot;)
strRet=request.querystring(&quot;return&quot;)
%>
<HTML>
<HEAD>
</HEAD>
<SCRIPT>
function postit(){
myform.submit();
}
</SCRIPT>
<BODY onLoad=&quot;postit()&quot;>
<FORM method=&quot;post&quot; action=&quot;<%= strRet %>&quot; name=&quot;myform&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;result&quot; value=&quot;<%= strRes %>&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;url&quot; value=&quot;<%= strRef %>&quot;>
</FORM>
</BODY>
</HTML>
www.vzio.com
star.gif

star.gif
 
Very cool!

Thanks for responding. Michael

MCSE NT\2000, UNIX, Novell
Java, JSP, ASP, VB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top