Solved

Get data and input-names from $_POST

Posted on 2010-08-16
2
305 Views
Last Modified: 2013-12-13
Hi,

Is it possible in PHP to get both the data and the input name when posting a form?

example,

if i got a form
<input name="a_field" value="a value" />
<input name="b_field" value="b value" />

On the page the form points to I want to catch all $_POST vars to an array like
$fields['fieldname'][0] = 'a_field';
$fields['fieldvalue'][0] = 'a value';
.... and so on
I know how to add the values to an array, but if I don't know the field names, is it possible to get them?

as when u do
<pre>
<?php
echo print_r($_POST);
?>
</pre>

u get both the filename and the value.

Hope my question is clear, please tell me and I try explain harder
0
Comment
Question by:Gudorian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
Shinesh Premrajan earned 400 total points
ID: 33444868
$i=0;
foreach($_POST as $k=>$y){
$fields['fieldname'][$i] = $k;
$fields['fieldvalue'][$i++] = $y;
}

Hope this helps
0
 
LVL 2

Author Closing Comment

by:Gudorian
ID: 33444958
Thx for the help and fast answer, this works perfectly

didn't know u could do the $i++ in "$fields['fieldvalue'][$i++] = $y;", thanks for that too :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

707 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