I'd like to post a form with inputs and files and retrieve in the destination page in the same order i've got in the form, for example:
<form id="form" method="post" action="">
Description file: <input type="text" name="input-1" value="description 1">
<br>
File: <input type="file" name="input-2">
<br>
<br>
Others data: <input type="text" name="input-3" value="some others unique data">
<br>
Description file: <input type="text" name="input-4" value="description 2">
<br>
File: <input type="file" name="input-5">
<br>
Description file: <input type="text" name="input-6" value="description 3">
<br>
File: <input type="file" name="input-7">
<br>
</form>
<?php
$post = $_POST;
$files = $_FILES;
foreach ( $post as $i => $value ) {
echo "Variables passed: " . $value . "<br>";
}
foreach ( $files as $i => $value ) {
echo "File: " . $value['name'] . "<br>";
}
?>
I'd like an output like:
Variables passed: description 1
File: file1.jpg
Variables passed: some others unique data
Variables passed: description 2
File: file2.jpg
Variables passed: description 3
File: file3.jpg
but i get this, cause i've 2 different foreach:
Variables passed: description 1
Variables passed: some others unique data
Variables passed: description 2
Variables passed: description 3
File: file1.jpg
File: file2.jpg
File: file3.jpg
This is only a simple example. I've a dynamic form where i can add inputs fields in differents ordering with a button.
Is there a way to mantain the same order to destination page?
UPDATE: i've edited my original post: It's not a rule there's always a File input after an input field text.
UPDATE 2: name
like input-1, input-2, input-3, input-4, ...
are automatically retrieved from mysql db when i click add button to insert a new input.. so they can be in different order like: input-1, input-3, input-2, input-4, ...