Solved

Get data and input-names from $_POST

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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

809 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