Kevin,
I think your basic approach is sub-optimal. I also don't agree with Brian's
suggestion of sticking everything into session variables.
Instead of posting the form to a new page - post the form back to itself.
That way you can easily repopulate the form elements if there's an error. If
there's no error, then you can Response.Redirect to the next page.
I would also write yourself a bunch of helper functions for generating the
form elements.
I know this sounds a little complex - I have a tutorial here (it's a bit
dated, but the fundamentals are sound):
http://www.adopenstatic.com/resources/code/UIValidation.asp
Cheers
Ken
-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Kevin Stevens
Sent: Monday, 12 March 2007 11:58 AM
To: thelist at lists.evolt.org
Subject: [thelist] Form validation using ASP
I have a simple booking form with text boxes, check boxes, text areas,
and dropdown boxes. I am trying to validate this information using ASP,
sending it to another page to do this, then redirecting back to the
first one if there is something missing in the required fields. The
trouble is, the text boxes retain their information, but the check boxes
are un-ticked, the text areas are blank, and the dropdowns go back to
their original Select setting. I have been scouring the Internet and
found some useful code but I can't get any of it to work. Here is an
example of what I've been trying
http://www.ratking.co.uk/manhire/test.asp , the code is below...
<%
if Session("Errors")=0 then
response.write "<html><span class='h3'>Fields marked <sup>*</sup> are
required.</span></html>"
else
'ERRORS WERE MADE SO LIST THEM IN THE REST OF THE TABLE
'reset our error counter
Session("Errors")="0"
response.write "<BR><span class='h4'>There are errors in your data. " & _
"Please make the following changes before " & _
"clicking the submit button:<br></span>"
response.write"<TABLE border=0 width=100% align='center'>"
If Session("badname") = "T" then
Response.write "<TR><TD><span class='h5'>The <strong>Name</strong>
field must be completed.</span>"
Response.write "</TD></TR>"
Session("badname")="F"
End If
If Session("badnumber") = "T" then
Response.write "<TR><TD><span class='h5'>The <strong>Number of
labourers needed</strong> field must be completed.</span>"
Response.write "</TD></TR>"
Session("badnumber")="F"
End If
end if
%>
<form name="mh_reserve" method="post" action="testform.asp">
<table>
<tr>
<td align="right" width="250"><span
class="h3">Name:<sup>*</sup>&nbsp;&nbsp;&nbsp;</span></td>
<td align="left"><input type="text" size="50" name="name"
id="name" value="<%=Session("name")%>"></td>
</tr>
<tr>
<td align="right" width="250"><span class="h3">Number of
labourers needed:<sup>*</sup>&nbsp;&nbsp;&nbsp;</span></td>
<td align="left"><select name="number" id="number"
value="<%=Session("number")%>">
<option>Select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
</tr>
<tr>
<td align="right"><span class="h3">Tick if
necessary:&nbsp;&nbsp;&nbsp;</span></td>
<td align="left"><input type="checkbox" name="vest"
value="<%=Session("vest")%>"><span class="h3">High visible vest<br>
<input type="checkbox" name="hat"
value="<%=Session("hat")%>">Hard hat<br>
<input type="checkbox" name="boots"
value="<%=Session("boots")%>">Steel toe-cap boots</span><br>
<input type="hidden" name="blank" value="">
</td>
</tr>
</table>
<input type="submit" name="submit" value="submit details">
</form>
If you need the code to the other page I'll post that as well.
Thanks
--
Kevin Stevens
kjs at ratking.co.uk
--
* * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/
For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !