Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Wednesday 14 May
MembersPro PayPal - ASP Membership software

asp.netPRO “Best ASP.NET Host” – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Self Referencing Forms

Here's how to create a self referencing form (ie a form that posts to itself or atleast the same page its on). We are also using one of the ServerVariables so that no matter what you call your page the form will post to the actual page it's on. I have called the page 'Form1.asp' though you can call your page whatever you like just as long as it has the .asp file extension.

The page checks to see if the form has been submitted, ie has the submit button called 'Submit' been clicked sending the value 'Submit', if it hasn't then hasitBeenSubmitted will have no value and the form will be displayed.

If it has been submitted the form won't be displayed and the value that was entered into the text box called 'Name' will be displayed.

Form1.asp

<%
hasitBeenSubmitted=request.Form("Submit")
If hasitBeenSubmitted="" Then
%>

<form action="<%=request.ServerVariables("SCRIPT_NAME")%>" method="post">
<input type="input" name="Name" value="">
<input type="submit" name="Submit" value="Submit">
</form>

<%
Else
Name=request.Form("Name")
response.write Name
End If
%>

As we said above we have used Request.ServerVariables("SCRIPT_NAME") which will tell us the name of our page and let the form know where to post the variables.

You could also just leave the action parameter empty i.e. <form action="" method="post"> which may be faster though I wanted to demonstrate how to use one of the ServerVariables.

LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software