Forum Moderators: open

Message Too Old, No Replies

Im tired and i need help

Server Side Form Validation

         

tonynoriega

3:58 pm on Nov 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you all know the story, i have a form, i use client side validation javascripts, and im still getting blank forms, and spam forms from spam bots.

i have read all the threads i could find on javascript Jumpstarts, searched for "Server Side Validation" and "Server Side Form Validation" and can not find any samples of what i need to be implementing on my site...if anyone has good direction, i would greatly appreciate at. Im using Classic ASP and submitting data to an SQL Dbase.

My form is simple and contains the following elements:

Name
Company
City
State
Phone
Email
How did you hear about us?
I am interested in:
Best time to contact me:

Then i utilize my form validation:

<script language="JavaScript" src="/includes/formValidation.js">
</script>
<script language="Javascript">
function ValidForm()
{var oForm = document._form;
oErrors= new Array();
lCount = 0;
ValidString(oForm.reqName.value,"Please fill in your Name.");
ValidString(oForm.city.value,"Please fill in your City.");
ValidString(oForm.state.value,"Please fill in your State.");
ValidString(oForm.reqAreaCode.value,"Please fill in your Area Code.");
ValidString(oForm.reqPhoneNumber.value,"Please fill in your complete Phone Number.");
ValidEmail(oForm.email.value,"Please fill in a Valid Email Address.");
if(!ShowErrors())
return true;
else
return false;
}
</script>

aspdaddy

6:36 pm on Nov 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Spam bots dont acre too much for javascript :)

Depends how sophisticated you want it. I write my own functions for lengths,formats,ranges ,blanks etc, and some error message code for nice error screens but at a basic level you can just go through each form item like this:

if request.form("name")="" then
Response.write "Name is blank, go back"
response.end
end if

ItzFX

7:34 pm on Nov 13, 2006 (gmt 0)

10+ Year Member



If you're worried about spam, you should add a captcha (or similar form authentication method) to your form.
Validating the form after submit the way aspdaddy wrote is also a good, way (one that I use), but doesn't get rid of all the spam...

Mechaworx

1:56 pm on Nov 14, 2006 (gmt 0)

10+ Year Member



Aspdaddy,

Like Tonynoriega I am no coding genius. Is there a way I can modify that code you suggested in the previous reply so that I can get it to loop through all the fields of a form or specific form fields to look for html code?

Thanks
Mechaworx

aspdaddy

8:57 pm on Nov 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can query the form item name and value only, you can use naming standards to help dtermine the types.

for each item in request.form
if left(item,3)="str" then ' check for string types
if request(item)="" then ' check for empty strings
end if
end if
Next