Reputation: 16234
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?
Upvotes: 0
Views: 295
Reputation: 75629
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.
Upvotes: 2