Link to home
Start Free TrialLog in
Avatar of sgriffin
sgriffinFlag for Ireland

asked on

VBScript Form Field Validation Help

Hi  ,

I need assitance with a form , have multiple fields that need to be filled in and then want to email using CDOSYS.

Any ideas?

Form below:

Cheers

Stephen!


*Departure Date:                  *Return Date:      

*Departure Time:                  *Return Time:      

*Departure Airport:      

*Destination Airport:      

*Return Airport:

*Name and Address of Customer/Course, etc.:


*Hotel Accommodation:      Yes:             No:


* Mandatory fields
ASKER CERTIFIED SOLUTION
Avatar of golfDoctor
golfDoctor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sgriffin

ASKER

Can you help me with a few fields using the example above?
The code provide by golfDoctor loops through all fields, so will validate entire form.  Try it!
where do I place this code above? can anyone provide an example ?
Whereever your form posts to, you would put that code.
If I were to use this example :

HTML>
<BODY>
<FORM ACTION="validate.asp" METHOD="POST">
Your Name: <INPUT TYPE="Text" NAME="name"><BR>
Your Email: <INPUT TYPE="Text" NAME="email"><BR>
Your ASP skills are:
<SELECT NAME="skills" SIZE="1">
<OPTION VALUE="I suck">I suck</OPTION>
<OPTION VALUE="Pretty bad">Pretty bad</OPTION>
<OPTION VALUE="Bad">Bad</OPTION>
<OPTION VALUE="Good">Good</OPTION>
<OPTION VALUE="Excelent">Excelent</OPTION>
<OPTION VALUE="Better than yours!">Better than yours!</OPTION>
</SELECT>
<BR>
Comment:<BR>
<TEXTAREA NAME="comment" COLS="20" ROWS="5" WRAP="VIRTUAL"></TEXTAREA><BR>
<INPUT TYPE="Submit" VALUE="Submit">
</FORM>
</BODY>
</HTML>


And I am posting back to the same page , where would I place the check code? As you can see Ive little experience with ASP form validation....

Cheers!
Validate.asp:

'golfDoctor code

<%
 for each i in request.form
        if i = "" then
               Response.write "Error, all information is necessary!"
               response.end
        end if
     next
   

Dim objCDOSYSCon

'Create e-mail server object
Set objCDOSYSMail= Server.CreateObject("CDO.Message")

'Who the e-mail is from
objCDOSYSMail.From = "yourname@yourdomain.com"  '<------------------hardcode your email to test

'Who the e-mail is sent to
objCDOSYSMail.To ="yourname@yourdomain.com"  '<------------------hardcode your email to test -- send to yourself!
'The subject of the e-mail
objCDOSYSMail.Subject ="This is the subject"
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
objCDOSYSMail.HTMLBody="<b>Hello</b>"  '<---------------------this line was wrong regardless of the rest
Send the e-mail
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing



%>
I tried the folllowing which doesnt work, where do I put the code ?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<HTML>
<BODY>
<FORM ACTION="ask.asp" METHOD="POST">
Your Name: <INPUT TYPE="Text" NAME="name"><BR>
Your Email: <INPUT TYPE="Text" NAME="email"><BR>
Your skills are:
<SELECT NAME="skills" SIZE="1">
<OPTION VALUE="A">A</OPTION>
<OPTION VALUE="B">B</OPTION>
</SELECT>
<BR>
Comment:<BR>
<TEXTAREA NAME="comment" COLS="20" ROWS="5" WRAP="VIRTUAL"></TEXTAREA><BR>
<INPUT TYPE="Submit" VALUE="Submit">
</FORM>
<% for each i in request.form
        if i = "" then
               Response.write "Error, all information is necessary!"
               response.end
        end if
     next
       %>
</BODY>
</HTML>
Sorry man, its all there....you'll figure it out.  Don't have time now.
Can anyone have a look at code posted and advise.

thanks

Stephen