PHP form processing - foreach  $_POST input field

Posted on 2009-06-29
Medium Priority
Last Modified: 2012-05-07
How do i go thru each input field that was submitted,  and access the fieldname and its value?

foreach  ($_POST)
  echo "FieldName = $xxx  --
       Value= $yyy <br>
Question by:willsherwood
LVL 28

Accepted Solution

gamebits earned 1000 total points
ID: 24741386
$namelist = "";
foreach($namelist as $value)
  $namelist .= "$value, ";
LVL 18

Assisted Solution

Hube02 earned 1000 total points
ID: 24741396
Or you could do the loop on $_POST itself.
foreach ($_POST as $key => $value) {
  // $key contains field name
  // $value contains the value of the field

Open in new window


Author Closing Comment

ID: 31598189
perfect, thanks all!

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
I recently worked on a Wordpress site that utilized the popular ContactForm7 (https://contactform7.com/) plug-in that only sends an email and does not save data. The client wanted the data saved to a custom CRM database. This is my solution.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question