Link to home
Start Free TrialLog in
Avatar of jkharodia
jkharodia

asked on

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
%>
Avatar of sajuks
sajuks

Try this
<%
If not isdate(Request.Form("txtStartDate2")) Then
Response.Redirect("Reports3.asp?error=" & notdate)
End if
%>
Avatar of jkharodia

ASKER

This doesn't work - still don't get the values
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.
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
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.



ASKER CERTIFIED SOLUTION
Avatar of sajuks
sajuks

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
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
// 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>
The vb has worked! Thanks for your help!
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
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