I have a server side script which checks that form fields have been completed. If not, an error page is called pointing out that 'Name' (for example) must be completed, and invites the user to 'go back' and complete the fields correctly.
However, I think we have all seen those error messages (normally in red type) next to the fields themselves - in other words, not another, separate asp file inviting the user to 'go back'.
In fact, some of the better sites keep those fields, which have been completed properly, intact - the visitor doesn't need to complete them again because only the erroneous fields are highlighted.
Has anybody on the forum any sample script (it needs to be server side, since I already have a couple of Javascripts on the page) which would serve my needs? It would need to redirect the visitor to another page if all form fields have been correctly completed.
<body>
<%
val = request.form("val")
if val = "yes" then
username = request.form("name")
thesubject = request.form("thesubject")
email = request.form("email")
if username = "" then
errorusername = "yes"
end if
if thesubject = "" then
errorthesubject = "yes"
end if
if email = "" then
erroremail = "yes"
end if
end if
if val = "" or errorusername = "yes" or errorthesubject = "yes" or erroremail = "yes" then
%>
<form name="form1" method="post" action="validationexample.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="31%">Name:</td>
<td width="69%">
<input name="Name" type="text" id="Name" value="<%=username%>">
<%
if errorusername = "yes" then
response.write "You didn't enter a user name"
end if
%>
</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<input name="thesubject" type="text" id="subject" value="<%=thesubject%>">
<%
if errorthesubject = "yes" then
response.write "You didn't enter the subject"
end if
%>
</td>
</tr>
<tr>
<td>Email Address:</td>
<td>
<input name="email" type="text" id="email" value="<%=email%>">
<%
if erroremail = "yes" then
response.write "You didn't enter your email address"
end if
%>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td>
<input type="submit" name="Submit" value="Submit">
<input name="val" type="hidden" id="val" value="yes"></td>
</tr>
</table>
</form>
<%else
response.write "Your form was completed with out errors"
end if
%>
</body>
</html>
My mistake was not to call the file validationexample.asp. Now that I have, it seems to be working fine. Thank you.
I now need to use something like:
<% Response.Redirect "abcpage.asp" %>
once the script has checked for errors and found none. I am concerned about where I put this, because I don't want the script to redirect to abcpage.asp until it has checked for all errors in the form. I think this means I need to turn off buffering also, otherwise the script will redirect the user anytime after the <HTML> tag.
hi,
so you want to redirect after validation. Would this be to a normal page in the site or to a thank you page. If its to a thank you page then you don't need to redirect as this thhank you page is included in the code i gave you:
<input name="val" type="hidden" id="val" value="yes"></td>
</tr>
</table>
</form>
<%
else
'---------------here is where you would put your thank you page. You can have a complete page here anything above this code will not be display if the form valitation came back as valid-------------------------------------------
response.write "Your form was completed with out errors"
end if
%>
</body>
if you don't want to display a thank you message and you need to redirect to a different page then replace your thankyou message with the code you already have:
<% Response.Redirect "abcpage.asp" %>
like bellow:
<input name="val" type="hidden" id="val" value="yes"></td>
</tr>
</table>
</form>
<%
else
'---------------here is where you would put your redirect code. If the form is valid then this line would be the only line that would run-------------------------------------------
Response.Redirect "abcpage.asp"
end if
%>
if you want to add variables to the querysting you do this:
var1 = "test"
Response.Redirect "abcpage.asp&var1="&var1&""
Bookmarks