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

validation in vbscript

Status
Not open for further replies.

frogggg

Programmer
Jan 17, 2002
182
US
I have an html page with a form gathering info. I want to validate that the fields are filled in and that the email is the correct format, but I do not want to use alerts. I want to redraw the page with the title of the field in red.
I understand that I have to do this part in asp. But, I want the page to display the values already entered. This means I have to write it to the recordset. But, I don't want to chance writing null fields to the recordset.
How can I write only those fields that are correct?
If anyone can point me to some already written code that would need to be modified, that would help very much.
Thanks.
 
you don't need to write to the recordset yet.

just move the form input fields to variables:

Dim sName
Dim sAddress
Dim sEmail
Dim sPhone

Dim sError


sName = Request.Form("Name")
sAddress = Request.Form("Address")
sEmail = Request.Form("Email")
sPhone = Request.Form("Phone")

If Request.Form("validate") = "yes" Then
' do your validation here....
' if field errors then
sError = "error message here"
End If

%>
<form name=&quot;formname&quot; method=&quot;post&quot; action=&quot;this.asp&quot;>
<input type=&quot;hidden&quot; name=&quot;validate&quot; value=&quot;yes&quot;>
<%
If sError <> &quot;&quot; Then
%>
<p><%=sError%></p>
<% End If %>
<input type=&quot;text&quot; name=&quot;Name&quot; value=&quot;<%=sName%>&quot;>
<input type=&quot;text&quot; name=&quot;Address&quot; value=&quot;<%=sAddress%>&quot;>
<input type=&quot;text&quot; name=&quot;Email&quot; value=&quot;<%=sEmail%>&quot;>
<input type=&quot;text&quot; name=&quot;Phone&quot; value=&quot;<%=sPhone%>&quot;>
<input type=&quot;submit&quot; name=&quot;Submit&quot;>
</form>
 
lobstah,

thanks for your help. Several questions.
I don't want to use error messages. I want to redraw the form with the label for that text box in red. How do I put a marker by that text box to know that it came back null?
Also, I didn't understand what
request.form(&quot;validate&quot;) did. Is it related to the hidden field? I'm not sure I understand what that's for either.
Also, what's the If sError <> &quot;?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top