Home All Groups Group Topic Archive Search About


Author
20 Dec 2005 12:23 AM
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.

Author
20 Dec 2005 1:51 AM
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!

<mene***@gmail.com> wrote in message
Show quote
news:1135038232.199443.19760@z14g2000cwz.googlegroups.com...
> 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.
>
Author
20 Dec 2005 2:54 AM
Larry Randolf
here is a working one that is ready to go.. might help you learn
http://www.powerasp.com/content/new/self_submitting_contact_form_using_cdosys.asp


<mene***@gmail.com> wrote in message
Show quote
news:1135038232.199443.19760@z14g2000cwz.googlegroups.com...
> 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.
>
Author
20 Dec 2005 1:50 PM
Paxton
mene***@gmail.com wrote:
Show quote
> 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.

AddThis Social Bookmark Button