tags:

views:

405

answers:

6

I have a form that has multiple fields, and for testing purposes is there a way I could print out the values entered in all the fields, without having to individually print each value.

+3  A: 

You should be able to do a var_dump($_REQUEST);

http://us2.php.net/manual/en/reserved.variables.request.php

http://us2.php.net/manual/en/function.var-dump.php

defeated
+4  A: 

For extra credit, I always have:

function pre($data) {
    print '<pre>' . print_r($data, true) . '</pre>';
}

Whenever I need to debug an array - which is very often - I just do pre($arr); to get a nicely formatted dump.

Paolo Bergantino
+5  A: 

print_r() / var_dump() are simple and gets the job done.

If you want a styled/dynamic option check out Krumo:

http://krumo.sourceforge.net/

A lot of developers use print_r() and var_dump() ... Krumo is an alternative: it does the same job, but it presents the information beautified using CSS and DHTML.

micahwittman
Interesting. Thxs for the link.
Darryl Hein
A: 

Besides using inline debug statements, you could also considering transient debugging, i.e. you could use an IDE with debug capabilities, like eclipse or zend studio. This way you could watch any variable you'd like to.

bye!

Hermooz
+1  A: 

If you're debugging a lot, I would recommend installing XDebug. It makes var_dump's very pretty and useful (giving you the type and length of the variable aswell).

Rexxars
A: 

This PHP code doesn't require any knowledge of the fields in the form that submits to it, it just loops through all of the fields, including multiple-choice fields (like checkboxes), and spits out their values.

<?php
// loop through every form field
while( list( $field, $value ) = each( $_POST )) {
   // display values
   if( is_array( $value )) {
      // if checkbox (or other multiple value fields)
      while( list( $arrayField, $arrayValue ) = each( $value ) {
         echo "<p>" . $arrayValue . "</p>\n";
      }
   } else {
      echo "<p>" . $value . "</p>\n";
   }
}
?>
Tim