RE: Question: Putting separate form elements into an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>
> > Have you tried naming your form elements such as
> > skill[], sky[] and slu[] ?
> > (You could also use skill[1], skill[2], skill[3]
> > etc... within your form.)
>
> Yes that makes sense.

Good.

This of course means you can build your form within a for loop (or similar).
So to place 10 skill text boxes in your form:
<?php
for ($x=0; $x<10; $x++)
{
  echo "<INPUT TYPE=\"TEXT\" NAME=\"skill[]\"><br/>";
  // Add other form elements

  // ** OR **

  echo "<INPUT TYPE=\"TEXT\" NAME=\"skill[<?=$x?>]\"><br/>";
  // Add other form elements
}
?>
>
> > You can just as easily store the arrays in your
> > $_SESSION if the processing
> > is to be done later.
>
> These are session , but put them into an array ?

$_SESSION['skills'] = $_POST['skill']; // Store the skill array
$_SESSION['skys'] = $_POST['sky']; // Store the sky array
$_SESSION['slus'] = $_POST['slu']; // Store the slu array

>
> > Note: Some form element types only pass a value if
> > ticked/checked/selected.
>
> The sky and slu are Dropdown Menu selects, so better
> with slu[1] or slu[x]?

Dropdown menus are fine (I believe) so you can simply use [] for your form
elements.

>
> > This will present problems if naming your form
> > elements with [], instead use
> > [x], [y] etc to keep all relevant form elements
> > together in the same array
> > indexes. (Am I making sense?, No?, time for bed
> > then...)
> >
>
> Sort of , I need to process.  Have a good night !

Don't forget to use print_r() and echo to see what your PHP script is
receiving from the form, it will help understand how to code your script. It
took me a while to get to grips with how form arrays work. (Let's hope I
haven't c0cked up here or that last statement will come back to haunt me !!)

Now I'm off ...  ZZZzzz

Graham

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux