|
Posted by Rik Wasmus on 10/31/07 22:08
On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:
> I have a working couple of pages (form submits 2 variables to the seco=
nd
> page using GET).
>
> page1 has two dropdowns (generated from MySQL db).
>
> page2 retrieves info from the database accordingly, depending on the =
> passed
> variables. Works fine.
>
>
> I need to ensure that the user has actually selected both variables on=
=
> page1
> from each of the drop down options on page1.
>
> empty() seems unable to do this because the default drop down options =
are
> "Select one", "Select the other".
>
> so on page2, if the user has NOT made any choices:
>
> echo "Values passed to GET method:<br />\n";
> reset ($_GET);
> while (list ($key, $val) =3D each ($_GET)) {
> echo "$key =3D> $val<br />\n";
> }
>
> gives me:
> Select one
> Select the other
>
>
> I can not see how to use empty() or isset() to resolve this, so...
>
> Any ideas how to ensure the user has selected something from both opti=
ons
> (without javascript)?
>
> I couldn't find anything in the manual but assume I'm looking in all t=
he
> wrong places for this.
Give the option a value 0 (well, it's more transparant/reliably checked =
=
then for the string 'Select one', and check if(!isset($_GET['option1']) =
|| =
$_GET['option1'] =3D 0) echo 'Please select an option.';
Or you could 'whitelist' options. So you have an array of possible =
options, and check:
$array =3D array(...);
if(!isset($_GET['option1']) || !in_array($_GET['option1'],$array)) echo =
=
'Please select.';
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|