Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

post

php

echo

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.

like image 609
Zoolander Avatar asked Feb 17 '12 17:02

Zoolander


People also ask

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

Simply add echo "<pre>"; before the var_dump() or print_r().

How can I get all post variables in PHP?

Try var_dump($_POST); to see the contents. If your post data is in another format (e.g. JSON or XML, you can do something like this: $post = file_get_contents('php://input'); and $post will contain the raw data.


1 Answers

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> 
like image 69
Jrod Avatar answered Sep 23 '22 10:09

Jrod