Validate Form redirect

Hi

I have a form which retrieves data from an Access database.  I am trying to validate the date parameter in the form so if the user enters a incorrect format an error is returned.  I have managed to do this with vb script, however when the page is redirected to the search page it looses the values entered by the user. How can i code so that the data entered by the user remains.

<%
If not isdate(Request.Form("txtStartDate2")) Then
Response.Redirect("Reports3.asp?error=notdate")'End If
%>
jkharodiaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sajuksCommented:
Try this
<%
If not isdate(Request.Form("txtStartDate2")) Then
Response.Redirect("Reports3.asp?error=" & notdate)
End if
%>
0
jkharodiaAuthor Commented:
This doesn't work - still don't get the values
0
sajuksCommented:
I assume you are trying to refer to the notdate value ? or are you referencing some thing else
with the above line of code you should be able to see something like this
http://localhost/Reports3.asp?id=21
then you can use the value of id.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

jkharodiaAuthor Commented:
I think u have misunderstood my question:  The error msg does appear on the search form when an invalid date is entered.  I have a search form on submit it goes to the results page, if the date entered is incorrect it redirects the user back to the search page. The problem i am having is that when u get re-directed to the search page, the other fields on the form which the user completed are blank hence the user has to fill them out again whent they are correct.  

I would like these fields to remain populate, similar function yo using the back button
0
sajuksCommented:
my bad, my vbscript is not too great can you try javascript soln ?
basically what i propose is this,
in the search page

<script language ="javascript">
if ( document.myForm.txtStartDate2.value = "")
{
return false;
}
else
{
return true
}
</script>
<body>
<form name=myForm action="Report3.asp" onSubmit = "return validate()">
<input type = "text name="txtStartDate2">
<input trype="submit">
</form>
</body>

this will prevent the search page submitting to the results unless the valdns are done.



0
sajuksCommented:
for vbscript soln, u could try this, not tested fully

Function myform_OnSubmit
   If IsDate(myform.txtStartDate2.value) = false Then
     msgbox "Enter Date Field Properly"
     myform_onSubmit = False
   End if
End Function

<form Name="myform" Action="Report3.asp" Method="Post" LANGUAGE ="VbScript">
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkharodiaAuthor Commented:
is there an function similar to isdate function in java script.  This function checks whther the date is in a valid format ie dd/mm/yyyy or dd/mm/yy
0
sajuksCommented:
// in javascript you need to write your own date valdn.theres no default date checker.
//check the below script written by one of our experts,validates for both dd/mm/yy and dd/mm/yyyy
// doesnt the above code work ( vbscript one ?)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--
function validate(val)
{
     mnthArray = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
     myarr = val.split("/")
     if(myarr.length!=3)
     {
          alert("The date needs to be entered in either dd/mm/yy or dd/mm/yyyy")
          return false;
     }
     day = myarr[0]/1;
     month = myarr[1]/1;
     year = myarr[2]/1;
     
     if(isNaN(month) || month>12)
     {
          alert("Invalid month");
          return false;
     }
     if(isNaN(day) || day>mnthArray[month-1])
     {
          alert("Invalid day")
          return false;
     }
     if(isNaN(year) || (myarr[2].length!=2 && myarr[2].length!=4))
     {
          alert("invalid year");
          return false;
     }
     alert("Validation completed");
     return true;
}

//-->
</SCRIPT>
</HEAD>

<BODY>
<INPUT TYPE="text" NAME="date" onblur = "validate(this.value)">
</BODY>
</HTML>
0
jkharodiaAuthor Commented:
The vb has worked! Thanks for your help!
0
jkharodiaAuthor Commented:
Sorry to bug u again:

How do i write this for two dates on my form, ie if Date1 is entered incorrectly then error saying date 1 is incorrect and if date 2 entered incorrectly then msg saying date 2 incorrect
0
sajuksCommented:
Is this what you wanted ?
Function myform_OnSubmit
   If IsDate(myform.txtStartDate1.value) = false Then
     msgbox "Enter Date1 Field Properly"
     myform_onSubmit = False
   End if

   If IsDate(myform.txtStartDate2.value) = false Then
     msgbox "Enter Date2 Field Properly"
     myform_onSubmit = False
   End if

End Function

Thanks for the points and grade
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.