• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

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
%>
0
jkharodia
Asked:
jkharodia
  • 6
  • 5
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now