[thelist] Form validation using ASP

Kevin Stevens kjs at ratking.co.uk
Mon Mar 12 13:58:15 CDT 2007


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





More information about the thelist mailing list