开发者

How to execute some code before posting a form using classic ASP

Using classic ASP, I want to execute some code before submitting to a form, below is my code. I am trying to store login credentials into cookies before posting the form to another page.

Please note that I am posting to an ASP.NET page that is held in a separate domain.

Another example, just to make this clearer. Let's say I want to validate fields before posting without using JavaScript.

<%
dim uname
uname= Request.Cookies("username")
%>

<FORM action="httppost_login.aspx" METHOD ="post" > 
<br />Username: <INPUT NAME ="username" SIZE ="30" maxlength="15" value="<% if uname <>"" then response.write(uname) %>" /> 
<br />Password: <INPUT NAME ="password" SIZE ="30" type=password maxlength="20" />
<br />
<INPUT TYPE ="SUBMIT" value="Login" name="btnSubmit" /> 
<input type="checkbox" name="remember" value="Remember my username" <%if uname <> "" then Response.Write("checked")%> />Remember my username
开发者_如何学Python</FORM> 

<%

If Request.Form("btnSubmit") <> "" Then
uname=Request.Form("username")
dim rememberme
rememberme = request.form("remember")
if rememberme <> "" and uname <> "" then
Response.Cookies("username") = uname 
Response.Cookies("username").Expires = Date() + 30   
end if
end if
%>


You can't run code easilly after the submit button is pressed.

This comes down to design. Your form action is:

httppost_login.aspx

The 'standard' way of achieving what you want is by having code on that page which handles the cookies/anything else.

I would usually give the form action a querystring:

<FORM action="httppost_login.aspx?action=login" METHOD ="post" >

Then on that page, have:

Dim strPageAction

strPageAction = request.querystring("action")

if(strPageAction = "login" then
    'Put your cookie code here, request.form("username") etc will still work!
end if


yes, a redirect page can post to a third party page using xmlhttp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜