views:

38

answers:

1

How to make the use of hidden variables as array for consecutive submission of data so that they can be used to display the records list.

I have a form with 4 text fields and a file upload field.. as i submit he form it should get appended to the list which needs to be displayed below the form, such that these values are NOT stored in the DB..

So in this case how can i use the post array to collect the data and display in the list below?

+2  A: 

You can use hidden input fields to pass the input data to the next page. Example:

<form method="POST">
Name: <input type="text" name="names[]" />
<input type="submit" value="Add" />
<?php
foreach ($_POST['names'] as $name)
{
        echo '<input type="hidden" name="names[]" value="'.$name.'"/>';
}
?>
</form>
<?php
print_r($_POST['names']);
?>

However, this will not work for the uploaded files. You have to save these as you get them and pass the filename in the form.

An alternative to this is to use sessions. These allow you to save some user data between page hits.

Sjoerd
@Sjoerd I did the same with my stuff but everytime i submit the form only one vale is obtained in the array.. why so?
OM The Eternity
I don't know. How would I know this? Does my code example works correctly? Do you have a small code example to show?
Sjoerd
Urs works Perfectly Fine..... The way u did did i need it that way only.. but when i tried it my stuff.. it stores only the current value and rest value gets deleted/replaced... could u figure it y?
OM The Eternity