My Little Help Desk - ASP Help Forum
My Little Help Desk - ASP Help Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 My Little Help Desk - ASP Help
 Active Server Pages
 VBScript Form Field Validation
 New Topic  Reply to Topic
Author Topic  

MasonX

3 Posts

Posted - 09/17/2006 :  10:35:14  Show Profile  Reply with Quote
How can I validate all the fields in my form are filled in? Well, not necessarily all, just the ones that I want to be required.

Thanks.

alorentz

66 Posts

Posted - 09/18/2006 :  19:57:25  Show Profile  Reply with Quote
This is my preferred method of form validation. I use server side code to loop through all required fields and build error message in loop:

<%
if request("submit1") <> "" then '<---THIS IS SUBMIT BUTTON NAME
for each fld in Request.Form
if left(fld, 4) = "req_" then 'CHECK FOR REQUIRED "req_"
if trim(Request.Form(fld)) = "" then
fldname = replace(fldname, "req_", "") 'REPLACE "req_"
fldname = replace(fldname, "_", " ") 'REPLACE "_"
errormsg = errormsg & "<br><font color=red size=2><B>" & ucase(fldname) & " is required *</b></font>" 'JUST USE NAME OF FIELD
end if
end if
next
end if
response.write "Error:" & errormsg
%>


Then you name your required field names with req_ in the name, like:

First Name: <input type=text name="req_first_name"><br>
Last Name: <input type=text name="req_Last_name"><br>
Company: <input type=text name="company"><br>

See that Company doesn't have req_, and therefore will not be required.

Hope that helps.
Go to Top of Page
  Topic  
 New Topic  Reply to Topic
Jump To:
My Little Help Desk - ASP Help Forum © mylittlehelpdesk.com Go To Top Of Page
Snitz Forums 2000