p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: form validation by type?


Message #1 by "Rob Blake" <rob_blake@h...> on Thu, 18 Apr 2002 15:46:00
Hi,
just wondering if there is any way that you can validate forms by the type 
of data entered. I am wanting to check the form so that if a user enters a 
string where there should be an int, the script picks up on it.

Many thanks

Rob Blake
Message #2 by "Gellings, C.O." <gellingsco@p...> on Thu, 18 Apr 2002 17:05:39 +0200
Yes, but you need to query all the fields or make two arrays, containing the
field names, one for string, one for integer and go through the motions in a
function or on submit (which will be in JavaScript) or when you return to
the next page which is defined by the submitbutton.
Your form can look like this:
<form>
<table>
<TR>
<td>item1<td><input type="text" value="??" name="xx"></td>
<td> item2<td> ...
etc
<tr>
<td>
         <input type="hidden" name="submitted" value="yes">
         <input type="submit" value="Save" name="submit">&nbsp;
         <input type="reset" value="Reset" name="reset">&nbsp;
         <input type="button" value="Cancel" >&nbsp;
</td>
</table>
</form>

at the top of the php file you refer to in the form's action property you
set:

if($submitted == "yes")
{
	bCheckItems();
}

Where bCheckItems() is the function in which you verify string and integer
values.

Grrrrrrrrrrrrrr,

Carl

> -----Original Message-----
> From: Rob Blake [mailto:rob_blake@h...]
> Sent: 18 April 2002 15:46
> To: beginning php
> Subject: [beginning_php] form validation by type?
>
>
> Hi,
> just wondering if there is any way that you can validate forms by
> the type
> of data entered. I am wanting to check the form so that if a user
> enters a
> string where there should be an int, the script picks up on it.
>
> Many thanks
>
> Rob Blake


  Return to Index