[PHP] Dynamic Arrays

2002-06-12 Thread Tom Ray

I have an array question. I want to use a dynamic array but I don't know 
how to do this. What I want to do is this, I want to write a form script 
that takes the elements of the form and submits them in the array then I 
want to do a loop and check to see if each element in the array has a 
value and then if it does bullocks for them, but if it doesn't then I 
want it to come to a screeching halt and tell them what dolts they are 
for missing a field. So basically I want to have a Required field option 
for the form. I'm still learning arrays and dynamic arrays are just 
throwing me and I can't find a good code example to work from.

TIA.


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




Re: [PHP] Dynamic Arrays

2002-06-12 Thread Miguel Cruz

On Wed, 12 Jun 2002, Tom Ray wrote:
 I have an array question. I want to use a dynamic array but I don't know 
 how to do this. What I want to do is this, I want to write a form script 
 that takes the elements of the form and submits them in the array then I 
 want to do a loop and check to see if each element in the array has a 
 value and then if it does bullocks for them, but if it doesn't then I 
 want it to come to a screeching halt and tell them what dolts they are 
 for missing a field. So basically I want to have a Required field option 
 for the form. I'm still learning arrays and dynamic arrays are just 
 throwing me and I can't find a good code example to work from.

Here's an example of what I think you're after:

  ?

  $fields = array(
'name' = 'Name: input name=name',
'age' = 'Age: input name=age',
'eyes' = 'Eyes: input type=radio name=eyes value=blue Blue
  input type=radio name=eyes value=brown Red'
);

  if (isset($_REQUEST['form_posted']))
  {
$missing_field = 0;
$good_fields = '';
foreach ($fields as $name = $html)
{  
  if (!($val = $_REQUEST[$name]))
  { 
if (!$missing_field)
  echo form method='post' action='{$_SERVER['PHP_SELF']}';
echo PThe following field is mandatory:br$html/p;
$missing_field = 1;
  }
  else
$good_fields .= input type='hidden' name='$name' value='$val';
}
  
if ($missing_field)
{
  echo $good_fields
. 'input type=submit name=form_posted/form';
  exit;
}

else   
{   
  echo pThank you for your input! Here's what we got:/pul;
  foreach (array_keys($fields) as $name)
echo li$name: {$_REQUEST[$name]}/li;
  echo '/ul';
}
  }  

  else
  {   
echo form method='post' action='{$_SERVER['PHP_SELF']}';
foreach ($fields as $f)
  echo $fbr;
echo 'input type=submit name=form_posted/form';
  }
   
  ?

miguel


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




Re: [PHP] Dynamic Arrays

2002-06-12 Thread Analysis Solutions

Hi Folks:

I was going to propose something similar.  Allow me to tweak:

 form 
 *input type=text name=my_array[foo] value=
 *input type=text name=my_array[bar] value=
 input type=text name=my_array[blankable] value=
 /form
 
 on you script page
 ?
   # $mand = array(foo, bar);
  $mand = array('foo', 'bar');

   # $cnt = count($mand);
   # for ($i = 0; $i  $cnt; $i++)
   #  if (!in_array($mand[$i], $my_array))
   #echo Error: You missed a required field - .$mand[$i].br\n;

$Prob = array();
while ( list(,$Key) = each($mand) ) {
   if ( empty($_POST[$Key]) ) {
  $Prob[] = $Key is a required field;
   }
}

if ( !empty($Prob) ) {
   echo ul\n;
   while ( list(,$Val) = each($Prob) ) {
  echo  li$Val./li\n;
   }
   echo /ul\n;
} else {
   #  Go ahead.  Fields are filled in.
}

 ?

Enjoy,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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