RE: [PHP] Preventing Identical Form Fields

2002-02-07 Thread Chris Wright

With javascript onSubmit, but that ain't php, so with
if($form1==$form2){sendthembackwitherrors()}

---
Christopher Wright
303 447 2496 x 107
www.netinfra.com

We'll take care of it.

Net Infrastructure has definitely helped our company, even though we're
not in the US, Net Infrastructure has been a key part in the success of
our business. Juan Carlos Saravia


-Original Message-
From: Dave Rosenberg [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 07, 2002 9:30 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Preventing Identical Form Fields


Pretty simple question, I think:

I'm creating a PHP form and want to prevent users from entering the same

response in more than one form field.  How can I have the script check 
for identical fields on POST?

Thanks
  Dave


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Preventing Identical Form Fields

2002-02-07 Thread Dave Rosenberg

Thanks Chris, but I have about 10 different fields and want to make sure 
none of those are the same.

Dave

Chris Wright wrote:

 With javascript onSubmit, but that ain't php, so with
 if($form1==$form2){sendthembackwitherrors()}
 
 ---
 Christopher Wright
 303 447 2496 x 107
 www.netinfra.com
 
 We'll take care of it.
 
 Net Infrastructure has definitely helped our company, even though we're
 not in the US, Net Infrastructure has been a key part in the success of
 our business. Juan Carlos Saravia
 
 
 -Original Message-
 From: Dave Rosenberg [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, February 07, 2002 9:30 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Preventing Identical Form Fields
 
 
 Pretty simple question, I think:
 
 I'm creating a PHP form and want to prevent users from entering the same
 
 response in more than one form field.  How can I have the script check 
 for identical fields on POST?
 
 Thanks
   Dave
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Preventing Identical Form Fields

2002-02-07 Thread Jeff Sheltren

Hi, I think that you could still use Chris' method, you will just have to 
do it in a loop.  Create an array of all the form fields, and then have a 
nested for loop which just checks that none of the elements are equal.

$numelements = count($fieldarray);
for($i = 0; $i  $numelements; $i++) {
 for($j = 0; $j  $numelements; $j++) {
 if($j != $i) {
 if($fieldarray[$i] == $fieldarray[$j]) {
 sendbackwitherrors();
 }
 }
 }
}

Hope that helps.

Jeff

At 11:42 AM 2/7/2002 -0500, Dave Rosenberg wrote:
Thanks Chris, but I have about 10 different fields and want to make sure 
none of those are the same.

Dave

Chris Wright wrote:

With javascript onSubmit, but that ain't php, so with
if($form1==$form2){sendthembackwitherrors()}
---



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Preventing Identical Form Fields

2002-02-07 Thread Jon Haworth

  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


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Preventing Identical Form Fields

2002-02-07 Thread Dave Rosenberg

Thanks y'all!  Everything's workin great now.

Jon Haworth wrote:

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
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php