Solved

Get data and input-names from $_POST

Posted on 2010-08-16
2
291 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:
shinuq 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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

747 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now