Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same page form submission

Status
Not open for further replies.

Tifa

Programmer
Oct 13, 2002
10
US
I am trying to get a form to verify that the name and email fields are valid before it submits the form to another page. But, I cannot get it to work. Here is my ASP:

<%
If Request.Form(&quot;SubmitButton&quot;) = &quot;Submit&quot; Then

Name = Request.Form(&quot;Name&quot;)
Email = Request.Form(&quot;Email&quot;)

If Name = &quot;&quot; Then
NameMessage = &quot;Invalid Name&quot;
End If

If InStr(Email,&quot;@&quot;)=0 Then
EmailMessage = &quot;Invalid E-Mail&quot;
End If

If NameMessage = &quot;&quot; and EmailMessage = &quot;&quot;
Response.Redirect(&quot;DisplayPage.asp?Name=&quot; & Name & &quot;&Email=&quot; & Email)
End If

End If

%>

<html>
<body>

<form method=&quot;get&quot; name=&quot;Logon&quot; action=&quot;FormPage.asp&quot;>
<table border=1 width=&quot;362&quot;>

Then comes the rest of the page.. any idea what I am doing wrong? It is giving me a 500 server error. Thanks!
 
you have GET as your action but use the POST request method (.form(&quot;&quot;)) _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
GET as method I mean.
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
Tifa,

You might want to apply the following validation function for checking your emails.

USAGE EXAMPLE:
If IsValidEmail(someone@somewhere.com) Then
<< continue >>
Else
<< error handler >>
End If

Function IsValidEmail(strEmail)

Dim blnIsValid
blnIsValid = True

If Len(strEmail) < 5 Then
blnIsValid = False
Else
If InStr(1, strEmail, &quot;@&quot;, 1) < 2 Then
blnIsValid = False
Else
If InStrRev(strEmail, &quot;.&quot;) < InStr(1, strEmail, &quot;@&quot;, 1) + 2 Then
blnIsValid = False
End If
End If
End If

IsValidEmail = blnIsValid
End Function _______________________________
regards,
Brian

AOL IM: FreelanceGaines

AG00280_.gif
 
Thanks BGaines for the tip. I will try it once I get the form working.

Onpnt, I changed the form method to &quot;post.&quot; I am still getting the http 500 internal server error. :( Any other ideas on what I may be doing wrong?
Thanks!
 
IE internet options
advanced tab
uncheck show friendly http errors

then tell us what the actual error is

btw take out the ( ) in the redirect. just do
response.redirect &quot; &quot;
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
I got it to work:

NOTE: I changed the variable &quot;Name&quot; to &quot;theName&quot;. I think Name might be a reserved word. Make the switch that onpnt is saying and verify your codebase with what I have here and it should work.

You are getting server errors, which it sounds like a setting needed to be made on your local server.

<%
If Request.Form(&quot;SubmitButton&quot;) = &quot;Submit Name and Email&quot; Then

theName = Request.Form(&quot;Name&quot;)
Email = Request.Form(&quot;Email&quot;)

response.write thename & &quot; :: &quot; & email

If theName = &quot;&quot; Then
NameMessage = &quot;Invalid Name&quot;
End If

If InStr(Email,&quot;@&quot;)=0 Then
EmailMessage = &quot;Invalid E-Mail&quot;
End If

If NameMessage = &quot;&quot; and EmailMessage = &quot;&quot; Then
Response.Redirect(&quot;DisplayPage.asp?Name=&quot; & theName & &quot;&Email=&quot; & Email)
End If

else
response.write &quot;here&quot;
End If

%>

<html>
<body>

<form method=&quot;post&quot; name=&quot;Logon&quot; action=&quot;postitself.asp&quot;>
<input type=&quot;text&quot; name=&quot;Name&quot; value=&quot;brian&quot;>
<input type=&quot;text&quot; name=&quot;Email&quot; value=&quot;someone@somewhere.com&quot;>
<input type=&quot;submit&quot; name=&quot;SubmitButton&quot; value=&quot;Submit Name and Email&quot;>
</form>
_______________________________
regards,
Brian

AOL IM: FreelanceGaines

AG00280_.gif
 
>>You are getting server errors, which it sounds like a setting needed to be made on your local server

the directions I gave are the settings that need to be made to show the actual error received.

sense we're throwing answers out there [smile]

the error was the last conditional statement
If NameMessage = &quot;&quot; and EmailMessage = &quot;&quot;
Response.Redirect(&quot;DisplayPage.asp?Name=&quot; & Name & &quot;&Email=&quot; & Email)
End If

notice the missing then

_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
Sorry onpnt, I jumped the gun. I didn't realize that you were training the debugging eye as you have done so much with me. :) _______________________________
regards,
Brian

AOL IM: FreelanceGaines

AG00280_.gif
 
[lol]

nothing to be sorry about. just a irritating thing I do alot that really isn't needed. Just seems to really help see those things after they are caught the first time by the programmer.

_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
Tifa

not completely sure on what you have in the rest of your page but there may be some things you want to do slightly different also.

here is a rewritten page for a something around these means
although bgaines72 is correct in the Name should not be used for a var name I do not believe it is a restricted word in ASP. not a good idea though
first the page should be a if statement. not the logical section. if the value of the submit button or as you see my hidden field is altered then the ASP validation script runs. else the page loads with the form.
<html>
<%
If Request.Form(&quot;submitted&quot;) <> &quot;Submit&quot; Then
%>
check for not = to value altered on submission
If false then load page

<head>
<script language=&quot;javascript&quot;>
function changeHidden() {
document.Logon.submitted.value = &quot;Submit&quot;;
alert(&quot;hidden field changed &quot;);
}
</script>
</head>
<body>
<form method=&quot;post&quot; name=&quot;Logon&quot; action=&quot;submit.asp&quot; onSubmit=&quot;return changeHidden()&quot;>
<input type=&quot;hidden&quot; name=&quot;submitted&quot;>
<input type=&quot;text&quot; name=&quot;Name&quot;>
<input type=&quot;text&quot; name=&quot;Email&quot;>
<input type=&quot;submit&quot; name=&quot;SubmitButton&quot; value=&quot;Submit Name and Email&quot;>
</form>
<%
else
if the hidden field was altered then run validator
Name = Request.Form(&quot;Name&quot;)
Email = Request.Form(&quot;Email&quot;)
If Name = &quot;&quot; Then
NameMessage = &quot;Invalid Name&quot;
End If

If InStr(Email,&quot;@&quot;)=0 Then
EmailMessage = &quot;Invalid E-Mail&quot;
End If

If NameMessage = &quot;&quot; and EmailMessage = &quot;&quot; Then
Response.write &quot;Name=&quot; & Name & &quot;&Email=&quot; & Email & &quot;<br> validation passed test&quot;
else
Response.write &quot;Name=&quot; & Name & &quot;&Email=&quot; & Email & &quot;<br> validation did not passed test&quot;
End If

end if
%>
</body>

just a bit of aditional advice
hope we've helped out a bit _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
I changed the &quot;friendly http errors&quot; and I was able to figure out that the missing THEN was the whole problem. I didn't even know what a friendly http error was. Well I'm glad you all were able to help me fix it.. thanks!!
 
Thanks onpnt, I just came from your website. I signed your guestbook and saw the email validation already. You have a nice site. I need to something soon. _______________________________
regards,
Brian

AOL IM: FreelanceGaines

AG00280_.gif
 
Thanks bgaines72 I just saw your insert. the compliments are always welcome. [smile]

btw: here's a great list of hosting services for ASP and such.
I currently am with halfpricehosting.com but am looking into som eother possibilities _________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
[sup] [/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top