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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validator

Status
Not open for further replies.

mwebbo1

Technical User
Jul 11, 2002
71
US
I am looking for a validator for asp mail (thread333-331445 or called form buttons) that I can add to the current code that I have. any suggestions. All I need is to make sure a name and email field are filled in, no numeric check or any of that. (onpnt, maybe you again?)
 
I usually like doing the validation above the field box, so you can have an extra cell above the filed, then do an if errName = True then show that cell, which contains an error message.. then when the form is submited just have it come back to the same page with a querystring, check if that exsists..then do your validation..

strName = Request.Form("frmName")
strEmail = Request.Form("frmEmail")


If Len(strName) > 3 then '# change 3 to whatever chr size
ErrName = True
End if

If Len(strEmail) > 5 AND InStr(strEmail, "@") > 0 then
ErrEmail = True
End if


<% If ErrName = True then %>
'# cell start
Error message here
'# cell end
<% End if %>


- Jason
www.vzio.com
star.gif
/ [wink]
 
hi there, well I wrote this up for you but it's messy and not the best way to validate something BUT it will work for this simple form.

give it a try
<html>
<head>
<script>
function val(x) {
if (x == &quot;&quot;) {
alert(&quot;You must fill in a email!&quot;);
document.form1.email.focus();
}
else
{
document.form1.submit()
}
}
</script>
</head>
<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;form1.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;send&quot;>
<table cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; border=&quot;1&quot; align=&quot;left&quot;>
<tr>
<td valign=&quot;top&quot; align=&quot;left&quot;>
<FONT color=#000000>
<FONT face=verdana,arial,helvetica size=2>
<STRONG>Email:</STRONG></FONT>
</td>
<td align=&quot;left&quot;><FONT face=verdana,arial,helvetica size=2>
<INPUT type=&quot;text&quot; name=&quot;email&quot; size=30>
</FONT></td>
</tr>
<tr>
<TD colspan=&quot;2&quot; align=center><br>

<a href=&quot;javascript:eek:nClick=val(form1.email.value)&quot;>Submit</a>
<a href=&quot;javascript:document.form1.reset()&quot;>Reset</a>
</TD></TR>
</table>
</form>
</body>
</html> You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
ok..not working, error is &quot;from addres cannot be blank&quot; on the results page. Or...if I do put in some phony address such as &quot;asfs&quot; error is &quot;550 Invalid local address&quot;...
It does not :alert: me before the page is submitted? Why?
The fields that I am using are name, company, email, and Phone. But has to have email with a dot and a com and that is fine, just want it to tell me before it goes to the result page.
 
here is the code that I am using
<%
dim name, company, email, phone, fax, address, comment, other
'dim name, title, company, address, city, state, zip, areacode
'dim phone, fax, email, how_they_heard, i_see
'dim comments


action = request(&quot;action&quot;)

if action = &quot;send&quot; then


name = request(&quot;name&quot;)
company = request(&quot;company&quot;)
email = request(&quot;email&quot;)
phone = request(&quot;phone&quot;)
fax = request(&quot;fax&quot;)
address = request(&quot;address&quot;)
comment = request(&quot;comment&quot;)
other = request(&quot;other&quot;)


recipient = &quot;mwebb@uliad.com&quot;
subject = &quot;REQUEST FORM&quot;
from = request(&quot;name&quot;)
fromem = request(&quot;email&quot;)


body = &quot;Name: &quot; & name & chr(10)
body = body & &quot;Company: &quot; & company & chr(10)
body = body & &quot;email: &quot; & email & chr(10)
body = body & &quot;Phone: &quot; & phone & chr(10)
body = body & &quot;Fax: &quot; & fax & chr(10)
body = body & &quot;URL: &quot; & address & chr(10)
body = body & &quot;Comment: &quot; & comment & chr(10)
body = body & &quot;Other: &quot; & other & chr(10)


SendMail recipient, body, subject, from, fromem
confirmsg = &quot;<font face=verdana,arial,helvetica color=A0522D size=2> Thank you.</font>&quot;

end if

sub SendMail(sRecipient, sBody, sSubject, sFrom, sFromem)

'on error resume next
Dim oEmail
Dim i

set oEmail = Server.CreateObject(&quot;SMTPsvg.Mailer&quot;)

oEmail.RemoteHost = &quot;mail.uliad.com&quot;
oEmail.FromAddress = sFromem
oEmail.Subject = sSubject
oEmail.AddRecipient sRecipient, sRecipient
oEmail.BodyText = sBody
oEmail.SendMail

response.write oEmail.Response

set oEmail = nothing

end sub

%>
 
sorry, I was under the impression the email was the only field you were passing. In that case what I gave you will not work. can you post the entire form. If you are looking to have a alert for the validation you will not be able to do it via the ASP side of things. The only way you can give a error on the server is if you write it to the page. So you have to go with a javascript validation before submiting the form to check for empty fields. Otherwise you can go with exactly what snowboardr gave you before the mail script is run and that will write the error to the page. I would personaly do it that way. You can do some redirecting and write the error above the form in regards to waht it was etc. You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
ok...well the thing is that this works, by that I mean it sends me information, and it is simple, and what I know about ASP is this and page includes, so adding that to the code is something that I am not familiar with. Is that something (snwoboardr code) that I add to some cells above the fields to display the message. Or/and do I add it/something else to the code at the top. (I am an idiot)But your help is much appreciated.
 
Ok.. Im guessing your a visual learner, so here we go..

At the top of our page you would do something like this:

<%
Dim strEmail, ErrEmail
Dim strName, ErrName

If Request.QueryString(&quot;action&quot;) = &quot;verify&quot; then

strName = Request.Form(&quot;frmName&quot;)
strEmail = Request.Form(&quot;frmEmail&quot;)

If Len(strName) > 3 then '# change 3 to whatever length
ErrName = True
End if

If Len(strEmail) > 5 AND InStr(strEmail, &quot;@&quot;) > 0 then
ErrEmail = True
End if


End if


%>

Now for the visual part, so you understand it.. at the beginning of the cell you put the If .. = true then %>
Then your cell with the message.. then at the end of the cell put end if.

verify.jpg


Hope you understand, and don't be hard on yourself, your not an idiot, you will get it. Hang in there.

- Jason
jason@vzio.com

www.vzio.com
star.gif
/ [wink]
 
oops..

those are suppose to be less then sign..

If Len(strName) < 3 then '# change 3 to whatever length
ErrName = True
End if

If Len(strEmail) < 5 AND InStr(strEmail, &quot;@&quot;) > 0 then
ErrEmail = True
End if www.vzio.com
star.gif
/ [wink]
 
oh boy im not with it, i forgot some steps..

in your form action=&quot;&quot; put this_form_name.asp?action=verify and before the first end if put


If ErrEmail <> True and ErrName <> True then
Response.Redirect &quot;formcomplete.asp&quot;
End if www.vzio.com
star.gif
/ [wink]
 
I really like that, it did not work for me, but I know what it is trying to do, the cell would only be there if the field is not filled in properly. One problem, I followed the directions and it did not work, I think that it is my code that is not letting it work. Is there some code that I can use, that will replace mine, that works with this validator, that I can use on all of my forms in the future.
 
Let me see all your code, and I will fix it for you. As far as using the form over again, I was just thinking about the same thing...I think it would be a good idea. Maybe a function or something. www.vzio.com
star.gif
/ [wink]
 
Do you have an email address that I could send it too?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top