Solved

Get data and input-names from $_POST

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
$_GET call between URL 3 45
powershell automatic variable for results 21 27
Group By Function Required in PDF Output 21 37
PHP substring 2 13
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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