Re: Preventing Identical Form Fields
| From: | Dave Rosenberg | Date: | Thu, 07 Feb 2002 19:27:55 +0000 |
| Subject: | Re: Preventing Identical Form Fields | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83894@lists.php.net to get a copy of this message | ||
Thanks y'all! Everything's workin great now.
Jon Haworth wrote:
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 JonWith 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.