Well, I posted my method recently (see Re: Required Fields Module), BUT
fliptop's methodology is better if your form has a group of checkboxes with
the same name or a multiple selection box (one example I didn't think of
that you pointed out, flipdog :)) or some other form design where your query
string will have multiple values under the same key name.
Big "D'oh!" on the '0' expression - that was a good QA catch!
Jason
----- Original Message -----
From: "fliptop" <[EMAIL PROTECTED]>
To: "Marcus Willemsen" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, July 09, 2001 1:07 PM
Subject: Re: Checking Form input.
> 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?