RE: [PHP] Preventing Identical Form Fields

From: Date: Thu, 07 Feb 2002 17:27:03 +0000
Subject: RE: [PHP] Preventing Identical Form Fields
Groups: php.general 
Request: Send a blank email to php-general+get-83877@lists.php.net to get a copy of this message
> > With javascript onSubmit, but that ain't php, so with > > if($form1==$form2){sendthembackwitherrors()} > Thanks Chris, but I have about 10 different fields and want to make sure > none of those are the same. You could brute force it: $ok = true; if ($field1 == $field2 || $field1 == $field3 || .... ) $ok = false; if ($field2 == $field3 || $field2 == $field4 || .... ) $ok = false; if ($ok == false) sendThemBackWithErrors (); Or you could use array_unique: // Substitute $_GET if you're using GET instead of POST ;-) if ($_POST != array_unique ($_POST)) sendThemBackWithErrors (); I'm not sure if this second one would work - I don't know if you can do straight comparisons of arrays - but the idea is to check that the submitted array is the same as the array with all the duplicates removed (if it isn't, there was a duplicate). HTH Jon

« previous php.general (#83877) next »