I'm new to ASP, but quickly catching on- I'm running thru "Dreamweaver 8 with ASP, ColdFusion and PHP" by Jefferey Bardzell- pretty decent book.
Currently I've got a ficticious form that has some simple validation included that sends the user back to the form with the erroneous fields highlighted with CSS.
I'm passing the error back via a Querystring; but would like to have the form retain the acceptable entries from the previous submission. What is the most common implementation of this? Do you do it with a cookie and set the initial value of the text boxes with a variable that starts out null? And is there a way to do it without cookies or a Querytstring?
Here's the form:
And here's the processor page guts:
More elegant solutions to this simple problem would be much appreciated!
Currently I've got a ficticious form that has some simple validation included that sends the user back to the form with the erroneous fields highlighted with CSS.
I'm passing the error back via a Querystring; but would like to have the form retain the acceptable entries from the previous submission. What is the most common implementation of this? Do you do it with a cookie and set the initial value of the text boxes with a variable that starts out null? And is there a way to do it without cookies or a Querytstring?
Here's the form:
Code:
<form id="form_tourprice" name="form_tourprice" method="post" action="tourprice_processor.asp">
<table width="60%" border="0" cellspacing="0" cellpadding="3">
<tr>
<%
If Request.QueryString("error") = "notNumeric" Or Request.QueryString("error") = "adultNotNumeric" Then
Response.Write("<td class=""error"">Number of Adults</td>")
Else
Response.Write("<td>Number of Adults</td>")
End If
%>
<td><input type="text" name="numAdults" id="numAdults" /></td>
</tr>
<tr>
<%
If Request.QueryString("error") = "notNumeric" or Request.QueryString("error") = "childrenNotNumeric" Then
Response.Write("<td class=""error"">Number of Children</td>")
Else
Response.Write("<td>Number of Children</td>")
End If
%>
<td><input type="text" name="numChildren" id="numChildren" /></td>
</tr>
<tr>
<td>Tour Name</td>
<td><select name="tourName" size="1" id="tourName">
<option value="500">Highlights of Argentina</option>
<option value="700">Highlights of Western Canada</option>
<option value="900">Egyptian Pyramids and More</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" name="Submit" id="Submit" value="Submit" /></td>
</tr>
</table>
</form>
And here's the processor page guts:
Code:
<%
If Not IsNumeric(Request.Form("numAdults")) and Not IsNumeric(request.Form("numChildren"))Then
Response.Redirect("tourprice.asp?error=notNumeric")
elseif Not IsNumeric(request.Form("numAdults")) Then
Response.Redirect("tourprice.asp?error=adultNotNumeric")
elseif Not IsNumeric(request.Form("numChildren")) Then
Response.Redirect("tourprice.asp?error=childrenNotNumeric")
End If
%>
<%
Dim numAdult, numChild, basePrice, tourPrice
numAdult = Request.Form("numAdults")
numChild = Request.Form("numChildren")
basePrice = Request.Form("tourName")
tourPrice = (numAdult * basePrice) + (numChild * basePrice)
%>
More elegant solutions to this simple problem would be much appreciated!