| 
	
 | 
 Posted by Jerim79 on 04/04/07 15:17 
On Apr 4, 10:06 am, Tyno Gendo <you@localhost> wrote: 
> Tyno Gendo wrote: 
> > Jerry Stuckle wrote: 
> >> A much easier way would be to just use an array: 
> 
> >>   <input name="age[]" ...> 
> 
> >> Then your answers will be in the array $_POST['age'] or $_GET['age'], 
> >> depending on how you submit the form. 
> 
> > That's a very good point.. I've used this once before also, top tip. 
> 
> I was just checking because I thought there was a reason I avoided the 
> age[] type method once, like perhaps it only sent form values that had 
> been filled in and were not blank, but this is not the case and it does 
> send all values, so as I went to the extent of testing it, here's the 
> code in case anyone needs it ;-) 
> 
> <?php 
>      if ($_SERVER["REQUEST_METHOD"] == "POST") { 
>          $age = $_POST["age"]; 
>          if ( is_array($age) ) { 
>              echo "There are " . count($age) . " elements in this 
> array."; 
>              for ($counter=0;$counter<count($age);$counter++) { 
>                  echo "<p>Age $counter is $age[$counter]</p>"; 
>              } 
>          } else { 
>              echo "age is not an Array"; 
>          } 
>      } 
> ?> 
> <form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post"> 
>      Age1<input type="text" name="age[]" value="10" /><br /> 
>      Age2<input type="text" name="age[]" value="20" /><br /> 
>      Age3<input type="text" name="age[]" value="30" /><br /> 
>      Age4<input type="text" name="age[]" value="40" /><br /> 
>      Age5<input type="text" name="age[]" value="50" /><br /> 
>      <input type="submit" /> 
> </form> 
 
You have all given me some very wonderful and useful ideas. Thank you 
all very much. (I just noticed the "Rate this post" ability.)
 
  
Navigation:
[Reply to this message] 
 |