How do I print all POST results when a form is submitted?

Zoolander picture Zoolander · Feb 17, 2012 · Viewed 335.7k times · Source

I need to see all of the POST results that are submitted to the server for testing.

What would be an example of how I can create a new file to submit to that will echo out all of the fields which were submitted with that form?

It's dynamic, so some fields may have a name/ID of field1, field2, field3, etc.

Answer

Jrod picture Jrod · Feb 17, 2012

All the values are stored in the $_POST collection

<?php print_r($_POST); ?>

or if you want something fancier that is easier to read use a foreach loop to loop through the $_POST collection and print the values.

<table>
<?php 


    foreach ($_POST as $key => $value) {
        echo "<tr>";
        echo "<td>";
        echo $key;
        echo "</td>";
        echo "<td>";
        echo $value;
        echo "</td>";
        echo "</tr>";
    }


?>
</table>