asp server

M

menelty

Can anyone help me?

I am doing a simple form for email and I want to validate it?
All the tutorials say I should use the following

<%
If request.form("name")="" or request.form("email")="" then
response.redirect "form.asp"
response.end
End if
%>

trouble is the server runs this code before the page loads and so the
page simply hangs and never loads as it always tries to redirect due to
the form elements initially being blank.

I could cheat and put in <yourname> in the name column but I cant
select a default value for my radio buttons.

thanks in advance,

menelty.
 
S

Steven Burn

<%
sPosted = Request.Querystring("lPost")
Select Case sPosted
Case "1" '// Posted
sName = Request.Form("txtName"): If Len(sName) < 1 Then Response.Redirect
"myform.asp?l=2"
sMail = Request.Form("txtMail"): If Len(sMail) < 1 Then Response.Redirect
"myform.asp?l=2"
'// Process the form
Response.Write "<b>Name:</b> " & sName & "<br>"
Response.Write "<b>Mail:</b> " & sMail & "<br>"
'// Notify after post
Response.Write "Thankyou, your comments have been sent"
Case Else '// Show the form
If sPosted = "2" Then Response.Write "<font color=""#ff0000""><b>Error:
you did something wrong ...</b></font><br><br>"
%>
<form
action="myform.asp?lpost=1&sid=<%=Request.ServerVariables("REMOTE_ADDR")%>"
method="post">
<input type="text" name="txtName"><input type="text" name="txtMail">
<input type="submit" name="submit" value="Submit">
</form>
<%
End Select
%>

Example:
http://mysteryfcm.plus.com/misc/myform.asp

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
P

Paxton

Can anyone help me?

I am doing a simple form for email and I want to validate it?
All the tutorials say I should use the following

<%
If request.form("name")="" or request.form("email")="" then
response.redirect "form.asp"
response.end
End if
%>

trouble is the server runs this code before the page loads and so the
page simply hangs and never loads as it always tries to redirect due to
the form elements initially being blank.

I could cheat and put in <yourname> in the name column but I cant
select a default value for my radio buttons.

thanks in advance,

menelty.

The simplest way is to check to see if the form's Submit button has
been pressed:

<%
If Request.Form("Submit") = "Submit" then
If Request.Form("name")="" or Request.Form("email")="" then
response.redirect "form.asp"
Else
'....process the form's content....
End if
End if
%>

However, this isn't very helpful. The visitor will just be presented
with a blank form again, so ideally you create a variable called
something like errormsg and apply the value "You didn't complete your
user name or email" and then write that to the page above the
re-presented form.
<%
If Request.Form("Submit") = "Submit" then
If Request.Form("name")="" or Request.Form("email")="" then
errormsg = "You didn't complete your user name or email"
Else
'....process the form's content....
End if
End if
Response.write errormsg
%>


/P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,372
Latest member
LucretiaFo

Latest Threads

Top