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

PhpPostEcho

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

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>

Solution 2 - Php

You could try var_dump:

var_dump($_POST)

Solution 3 - Php

Simply:

<?php
    print_r($_POST);

    //Or:
    foreach ($_POST as $key => $value)
        echo $key.'='.$value.'<br />';
?>

Solution 4 - Php

You may mean something like this:

<?php
    $output = var_export($_POST, true);
    error_log($output, 0, "/path/to/file.log");
?>

Solution 5 - Php

You could use something as simple as this

<?php
   print_r($_POST);
?>

This would make it a bit more viewable:

<?php
   echo str_replace('  ', '&nbsp; ', nl2br(print_r($_POST, true)));
?>

Solution 6 - Php

You can definitely use var_dump, but you mentioned you are in front-end development. I am sure you would know this, but just as a reminder, use Firefox's Firebug or Chrome's / Internet Explorer's developers tool and check for the post. Post goes through hearders, and you should be able to check it from there too.

Solution 7 - Php

if (! function_exists('d'))
{
    // Debugger
    function d($var, $exit = 0)
    {
        // Only output on localhost
        if ($_SERVER['HTTP_HOST'] != 'localhost')
        {
            return;
        }

        echo "\n[degug_output_BEGIN]<pre>\n";
        echo var_export($var, 1);
        echo "\n</pre>[degug_output_END]\n";

        if ($exit)
            exit;
    }
}

// Call:
d($_POST);

Bonus: Check debug_backtrace() too add tracing to your debugging.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZoolanderView Question on Stackoverflow
Solution 1 - PhpJrodView Answer on Stackoverflow
Solution 2 - PhpFrancisco ValdezView Answer on Stackoverflow
Solution 3 - PhpNicolasView Answer on Stackoverflow
Solution 4 - PhpPoniView Answer on Stackoverflow
Solution 5 - PhpVexView Answer on Stackoverflow
Solution 6 - Phpuser1074115View Answer on Stackoverflow
Solution 7 - PhpIgor ParraView Answer on Stackoverflow