Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation

Status
Not open for further replies.

showers10

Programmer
Jul 25, 2011
1
Please i need help on how to validate my forms thanx..... Below is the form structure.

<form action="thanks.php" method="post" enctype="multipart/form-data" onsubmit='return formValidator()'>
<table width="580" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="270" class="txt"><strong>Name of Orphanage Institution :</strong></td>

<td width="310"><label>
<input type="text" id='oname' name="oname" size="40"/>
</label></td>
</tr>
<tr>
<td class="txt"><strong>Name of Director-In-Charge :</strong></td>
<td><label>
<input type="text" id='dname' name="dname" size="40"/>

</label></td>
</tr>
<tr>
<td class="txt"><strong>Name of Social Welfare Supervisor :</strong></td>
<td><label>
<input type="text" id='swname' name="swname" size="40"/>
</label></td>
</tr>

<tr>
<td class="txt"><strong>Date of 1<sup>st</sup> Social Welfare Inspection :</strong></td>
<td><label>
<input type="text" id='insname' name="insname" size="40"/>
</label></td>
</tr>
<tr>

<td class="txt"><strong>Number of residential children :</strong></td>
<td><label>
<input type="text" id='nores' name="nores" size="40"/>
</label></td>
</tr>
<tr>
<td class="txt"><strong>Number of non-residential children :</strong></td>
<td><label>

<input type="text" id='nonres' name="nonres" size="40"/>
</label></td>
</tr></table>
<table><tr>
<td width="350" class="txt"><strong>REASON FOR BEING IN THE ORPHANAGE :</strong></td>
<td width="50" class="txt"> <strong>TICK : </strong></td>
<td width="170" class="txt"> <strong><center>NUMBER : </center></strong></td>

</tr>
<tr>
<td width="355" class="txt"><strong>Abandoned :</strong></td>
<td width="50"><label><center>
<input type="checkbox" id='chk1' name="chk1"></center>
</label></td>
<td width="170"><label><center>
<input type="text" id='noaban' name="noaban" size="20" /></center>

</label></td>
</tr>
<tr>
<td class="txt"><strong>Orphaned :</strong></td>
<td width="50"><label><center>
<input type="checkbox" id='chk2' name="chk2"></center>
</label></td>
<td width="170"><label><center>

<input type="text" id='noorph' name="noorph" size="20" /></center>
</label></td>
</tr>
<tr>
<td class="txt"><strong>Surrendered :</strong></td>
<td width="50"><label><center>
<input type="checkbox" id='chk3' name="chk3"></center>
</label></td>

<td width="170"><label><center>
<input type="text" id='nosur' name="nosur" size="20" /></center>
</label></td>
</tr>
<tr>
<td class="txt"><strong>In need of care and protection :</strong></td>
<td width="50"><label><center>
<input type="checkbox" id='chk4' name="chk4"></center>

</label></td>
<td width="170"><label><center>
<input type="text" id='incare' name="incare" size="20" /></center>
</label></td>
</tr></table>

<table><tr>
<td width="580" class="txt" colspan="4"><strong>CHILDREN THAT COULD BE RESETTLED :</strong></td></tr>
<tr>

<td width="244" class="txt"><center><strong>NAME</strong></center></td>
<td width="30" class="txt"><center><strong>AGE</strong></center></td>
<td width="36" class="txt"><center><strong>SEX</strong></center></td>
<td width="268" class="txt"><center> <strong>GUARDIAN</strong></center></td>
</tr>
<tr>

<td width="244"><label>
<textarea name="resname" cols="32" id='resname'></textarea>
</label></td>
<td width="30"><label>
<textarea name="resage" cols="4" id='resage'></textarea>
</label></td>
<td width="36"><label>
<textarea name="resex" cols="7" id='resex'></textarea>

</label></td>
<td width="268"><label>
<textarea name="resguard" cols="33" id='resguard'></textarea>
</label></td>
</tr>
<tr>
<td width="580" class="txt" colspan="4"><strong>ADOPTED CHILDREN :</strong></td></tr>
<tr>

<td width="244" class="txt"><center><strong>NAME</strong></center></td>
<td width="30" class="txt"><center><strong>AGE</strong></center></td>
<td width="36" class="txt"><center><strong>SEX</strong></center></td>
<td width="268" class="txt"><center> <strong>IS THERE ANY CONSENT FORM</strong></center></td>
</tr>
<tr>

<td width="244"><label>
<textarea name="adoname" cols="32" id='adoname'></textarea>
</label></td>
<td width="30"><label>
<textarea name="adoage" cols="4" id='adoage'></textarea>
</label></td>
<td width="36"><label>
<textarea name="adosex" cols="7" id='adosex'></textarea>

</label></td>
<td width="268"><label>
<textarea name="adoconsent" cols="33" id='adoconsent'></textarea>
</label></td>
</tr>
<tr>
<td width="580" class="txt" colspan="4"><strong>SURRENDERED CHILDREN :</strong></td>
</tr>

<tr>
<td width="244" class="txt"><center><strong>NAME</strong></center></td>
<td width="30" class="txt"><center><strong>AGE</strong></center></td>
<td width="36" class="txt"><center><strong>SEX</strong></center></td>
<td width="268" class="txt"><center> <strong>IS THERE A LEGAL BACK-UP?</strong></center></td>
</tr>

<tr>
<td width="244"><label>
<textarea name="surname" cols="32" id='surname'></textarea>
</label></td>
<td width="30"><label>
<textarea name="surage" cols="4" id='surage'></textarea>
</label></td>
<td width="36"><label>

<textarea name="sursex" cols="7" id="sursex"></textarea>
</label></td>
<td width="268"><label>
<textarea name="surlegal" cols="33" id='surlegal'></textarea>
</label></td>
</tr>
<tr>
<td width="580" class="txt" colspan="4"><strong>HOW MANY CHILDREN ARE IN NEED OF URGENT MEDICAL ATTENTION :</strong></td>

</tr>
<tr>
<td width="244" class="txt"><center><strong>NAME</strong></center></td>
<td width="30" class="txt"><center><strong>AGE</strong></center></td>
<td width="36" class="txt"><center><strong>SEX</strong></center></td>
<td width="268" class="txt"><center> <strong>BRIEF MEDICAL REPORT (if any)</strong></center></td>

</tr>
<tr>
<td width="244"><label>
<textarea name="urgname" cols="32" id='urgname'></textarea>
</label></td>
<td width="30"><label>
<textarea name="urgage" cols="4" id='urgage'></textarea>
</label></td>

<td width="36"><label>
<textarea name="urgsex" cols="7" id="urgsex"></textarea>
</label></td>
<td width="268"><label>
<textarea name="urgrep" cols="33" id='urgrep'></textarea>
</label></td>
</tr></table>
<table width="580"> <tr>

<td width="580" class="txt" colspan="4"><strong>LEGAL AND FINANCIAL REQUIREMENTS :</strong></td>
</tr>
<tr>
<td width="332" class="txt"><center><strong>HAS YOUR INSTITUTION:</strong></center></td>
<td width="30" class="txt"><center><strong>YES</strong></center></td>
<td width="36" class="txt"><center><strong>NO</strong></center></td>
<td width="180" class="txt"><center> <strong>NOTES</strong></center></td>

</tr>
<tr>
<td width="332" class="txt">Been registered with the Registrar General</td>
<td width="30"><label><center>
<input type="checkbox" id='chk5' name="chk5"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk6' name="chk6"></center>

</label></td>
<td width="180"><label>
<input type="text" id='rgenote' name="rgenote" size="29" />
</label></td>
</tr>
<tr>
<td width="332" class="txt">A copy of its regulations attached</td>
<td width="30"><label><center>

<input type="checkbox" id='chk7' name="chk7"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk8' name="chk8"></center>
</label></td>
<td width="180"><label>
<input type="text" id='regnote' name="regnote" size="29" />
</label></td>
</tr>

<tr>
<td width="332" class="txt">A copy of its By-Laws attacthed</td>
<td width="30"><label><center>
<input type="checkbox" id='chk9' name="chk9"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk10' name="chk10"></center>
</label></td>

<td width="180"><label>
<input type="text" id='bylawnote' name="bylawnote" size="29" />
</label></td>
</tr>
<tr>
<td width="332" class="txt">A copy of its constitution attacthed</td>
<td width="30"><label><center>
<input type="checkbox" id='chk11' name="chk11"></center>

</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk12' name="chk12"></center>
</label></td>
<td width="180"><label>
<input type="text" id='consnote' name="consnote" size="29" />
</label></td>
</tr>
<tr>

<td width="332" class="txt">A management committee (particulars attached)</td>
<td width="30"><label><center>
<input type="checkbox" id='chk13' name="chk13"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk14' name="chk14"></center>
</label></td>
<td width="180"><label>

<input type="text" id='comnote' name="comnote" size="29" />
</label></td>
</tr>
<tr>
<td width="332" class="txt">Work with its local Social Welfare Officer</td>
<td width="30"><label><center>
<input type="checkbox" id='chk15' name="chk15"></center>
</label></td>

<td width="36"><label><center>
<input type="checkbox" id='chk16' name="chk16"></center>
</label></td>
<td width="180"><label>
<input type="text" id='swonote' name="swonote" size="29" />
</label></td>
</tr>
<tr>
<td width="332" class="txt">Been auditored</td>

<td width="30"><label><center>
<input type="checkbox" id='chk17' name="chk17"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk18' name="chk18"></center>
</label></td>
<td width="180"><label>
<input type="text" id='audnote' name="audnote" size="29" />
</label></td>

</tr>
<tr>
<td width="332" class="txt">Keeps record of Accounts correctly</td>
<td width="30"><label><center>
<input type="checkbox" id='chk19' name="chk19"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk20' name="chk20"></center>

</label></td>
<td width="180"><label>
<input type="text" id='accnote' name="accnote" size="29" />
</label></td>
</tr>
<tr>
<td width="332" class="txt">Keeps record of children correctly</td>
<td width="30"><label><center>

<input type="checkbox" id='chk21' name="chk21"></center>
</label></td>
<td width="36"><label><center>
<input type="checkbox" id='chk22' name="chk22"></center>
</label></td>
<td width="180"><label>
<input type="text" id='childnote' name="childnote" size="29" />
</label></td>
</tr></table>

<table width="580"> <tr>
<td width="300" class="txt" colspan="2"><strong>HOW MUCH DO YOU SPEND ON :</strong></td>
<td width="" class="txt" colspan="2"><strong>PER MONTH ¢ </strong></td>
</tr>
<tr>
<td width="300" class="txt" colspan="2">Food</strong></td>
<td width="" class="txt" colspan="2"><label>

<input type="text" id='food' name="food" size="20" />
</label></td>
</tr>
<tr>
<td width="300" class="txt" colspan="2">Clothing</td>
<td width="" class="txt" colspan="2"><label>
<input type="text" id='cloth' name="cloth" size="20" />
</label></td>

</tr>
<tr>
<td width="300" class="txt" colspan="2">Education</td>
<td width="" class="txt" colspan="2"><label>
<input type="text" id='educ' name="educ" size="20" />
</label></td>
</tr>
<tr>

<td width="300" class="txt" colspan="2">NHIS</td>
<td width="" class="txt" colspan="2"><label>
<input type="text" id='nhis' name="nhis" size="20" />
</label></td>
</tr>
<tr>

<td colspan="2">&nbsp;</td>

<td colspan="2">&nbsp;</td>
</tr>

<tr>

<td align="right" colspan="2"><label>

<input type="submit" value="Submit" />

</label></td>

<td colspan="2"><label>

<input type="submit" name="Submit2" value="Reset" />

</label></td>
</tr>
</table>
</form>
 
You CAN do form validation in JavaScript, but that is just a way to make it seem more responsive to the user.

If all you did was validate using JavaScript, all I would have to do is disable JavaScript (which many people already do) - and then NO validation would get done and you would get bad data in your processing script.

Validation should ALWAYS be done on the server before you handle the data. You can still use JavaScript validation, but you still need to have it on the server as well - to protect yourself from errors.

In your case I would put validation within thanks.php.

See the following as an example of php validation:
 
My 2c.
Use a combo..
HTML5/css3 (works for a lot of modern browsers - none are consistant across the board - all validate different types of input box's better than others.. No clear winner - but for somethings opera has teh coolest features)
(as a starting point)

Javascript / JQuery (via jquery validation plugin)
( -
there are a few.

and Server side.

Idea being
If the HTML in the browser works then it dosn't matter if java script is turned off.
Java script is the next level as it can save a round trip to the server making you page more responsive and ensures validation
and
last server side..
If the other two methods can't work due to browsers and browser settings then you have a 100% reliable backup.

My 2c

Rob
 
Most importantly
data MUST be validated server side as there is no way to guarantee the provided data has been posted from your web page & is not being spoofed.

carefully crafted invalid data could be used to compromise your back-end database or even your whole server.

The 1st rule of from processing is trust no-one!

I do not Have A.D.D. im just easily, Hey look a Squirrel!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top