Re: [PHP] checking $_POST variables

2003-03-15 Thread Justin French
As explained already, not a good idea :)

Also, if someone makes a copy of your form and excludes one of the fields,
then it won't be set in POST at all.

Keep an array of the fields you have in the form.  I choose to set the field
as the key, and then for the value either 1 (required) or 0 (not required):

?
// formPostArray.php
$formPostElements = array(
'first' = 1,
'last' = 0,
'email' = 1',
'age' = 0,
'sex' = 0
);
?

Then include it where needed:

?
include('formPostArray.php');
?

Then use the array to check POST values are set, or better still, not empty:

?
$error = 0;
foreach($formPostElements as $key = $val)
{
if($val)
{
if(empty($_POST[$key]) // could also be if(!isset($_POST[$key]))
{
$error = 3;
}
}
}
if($error)
{
header(Location: signup.php?error={$error});
exit();
}
?


In your case, street2 could be set to 0, and the rest set to 1.

You may also find that you can use the same array to write all your form
code as well, with a little work!!


Justin



on 15/03/03 6:26 AM, drparker ([EMAIL PROTECTED]) wrote:

 I'm running this script to make sure all fields are filled in on a form:
 
 foreach($_POST as $p)
 {
 if(!$p)
 {
 header(Location: signup.php?error=3);
 exit();
 }
 }
 
 But I need to exclude one field on the form from being checked -
 Street2.  How could I do this?
 
 


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



[PHP] checking $_POST variables

2003-03-14 Thread drparker
I'm running this script to make sure all fields are filled in on a form:

foreach($_POST as $p)
{
  if(!$p)
 {
  header(Location: signup.php?error=3);
  exit();
 }
}

But I need to exclude one field on the form from being checked -
Street2.  How could I do this?



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



Re: [PHP] checking $_POST variables

2003-03-14 Thread Ernest E Vogelsinger
At 20:26 14.03.2003, drparker said:
[snip]
I'm running this script to make sure all fields are filled in on a form:

foreach($_POST as $p)
{
  if(!$p)
 {
  header(Location: signup.php?error=3);
  exit();
 }
}

But I need to exclude one field on the form from being checked -
Street2.  How could I do this?
[snip] 

That's generally not a good idea because depending on the type of control
empty input fields will not be available in the $_POST array (e.g.
unchecked checkboxes are _not_ sent by the browser).

You should rather have a list of input variables that need to be filled and
compare $_POST against this.


-- 
   O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



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



Re: [PHP] checking $_POST variables

2003-03-14 Thread Liam Gibbs
 That's generally not a good idea because depending on the type of control
 empty input fields will not be available in the $_POST array (e.g.
 unchecked checkboxes are _not_ sent by the browser).

 You should rather have a list of input variables that need to be filled
and
 compare $_POST against this.

I'd agree with this, but just in case this is an absolute necessity, and a
sure thing, have you tried:

foreach($_POST as $key=$value) {
...
}

I haven't tried that, but it may work.


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