If-else statments in ASP

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
Ok, when submitting a form, how can I to see if the user filled out all the required fields? I'm more familiar with PHP, but a friend of mine needs help. Isn't it just a matter of writing a function that will check to see if the appropriate fields are filled out?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
if request.form("myformfieldname") = "some string to check" then
if request.form("mynextformfieldname") = "some other string to check then
Response.write("All fields filled out correctly.")
else Response.write("mynextformfieldname was filled out incorrectly")
end if
else Reponse.write("myformfieldname was filled out incorrectly")
end if

You can do that, or you can do a
for a = 1 to Request.form.count
some data checking in here
Next
 

LuckyTaxi

Diamond Member
Dec 24, 2000
6,044
23
81
let's say we want to check to see if the field is blank. In php it's if(!name || !email || !number), the "!" telling the computer that it's an empty value.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
You can also do something like

ecount = 0
estring = "The following field(s) were not filled out" + vbCrLf

and for each "if" that fails, add to ecount and append to estring.

after all checks

if ecount > 0 then
Response.Write(estring)

else
... process the form

end if
 

DJFuji

Diamond Member
Oct 18, 1999
3,643
1
76
check the page on the client first using javascript clientside validation. Then double up by validating the data using VBScript/ASP code to ensure things come in accurately.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: DJFuji
check the page on the client first using javascript clientside validation. Then double up by validating the data using VBScript/ASP code to ensure things come in accurately.
That part is crucial since people used to scam early e-commerce websites by altering the client data to change prices or even run malicious code.

People also spoofed client data to turn a form that emailed data into an open relay for spam. The list of hacks from altered / bad client side data is pretty long.