Solved

Get data and input-names from $_POST

Posted on 2010-08-16
2
299 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
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to dynamically set the form action using jQuery.

791 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