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

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Get your best asp web hosting provider now and save 25%