Marcus Willemsen wrote:
> 
> Probably I got it all wrong but can someone give me some general advise how
> to handle such problems? Use a JavaScript to check the input?

you can use javascript, but that won't work if the user has disabled
javascript in their browser.

i use a 3-step process to validate form data.  assume the query string
is as such:

/cgi-bin/somefile.cgi?key1=value1&key2=value2&key2=value3

1)  put the form key-value pairs into an array.  use a pre-declared
required_params hash so you only push on the key-value pairs you want
(the user could easily post a query string with more key-value pairs
than you're interested in).  assuming the original query string contains
only the key-value pairs i'm intersted in, the array will look like
this:

@params = (key1, value1, key2, value2, key2, value3);

2)  create a hash using the @params array.  the hash will look like
this:

%params = (
  key1 => value1,
  key2 => [ value2, value3 ]
);

notice the 1st value is a scalar, but the second is a ref to an array
that contains all values.

3)  check the %params hash against the pre-declared required_params hash
to see if all the required values are defined and have a certain
length.  in other words, don't just check to see if they're true/false,
otherwise it will never accept a value of '0' (which could be a valid
answer).

if everything is kosher, then your values are in a hash ready to be used
in the program.

like i said at the beginning, this is the method i use.  tmtowtdi! 
anyone else care to post their method?

Reply via email to