Automatically display form data with PHP

This is a simple PHP  script to automatically display (dump output)  data submited from a html form.

The form setup

  • all inputs (form fields) need to have the same name with [] at the end to turn it into an array,  e.g <input type=text name=formdata[]>

formq.html content

<form method=post action=showme.php>
Name: <input type=text name=formdata[]><br>
Email: <input type=text name=formdata[]><br>

<input type=submit value=ok>
</form>

The Script setup

showme.php content

<?php
$data = $_POST['formdata']; # get value from the form fields

foreach ( $data as $key => $value ) { # loop through array collecting the results

echo  “$value<br>”;  # output the data  – print to page
}
?>

Technorati Tags: , , , ,

QR Code for this page.


Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>