Solved

PHP Get Values from Associative Array

Posted on 2013-12-17
2
444 Views
Last Modified: 2013-12-17
I have a form that collects amounts paid here...

http://buildmomentum.org/register/lc/group_payment.php?id_church=ORG101&total_group_payment=100

When the button is clicked, I need to give the person entering the amounts an opportunity to check their entry.  How do I convert the associative array into variables I can show the user, then pass on to the next page for processing?

I could post code I've tried, but I've tried so many different ways of doing a "For Each" loop and "Implode" from $_POST that I don't know what code to post.  At this point, I think it's easier to start from scratch.

Thanks,

Steve
0
Comment
Question by:stkoontz
[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 82

Accepted Solution

by:
hielo earned 500 total points
ID: 39724054
try:
if(isset($_POST['payment']) && $_POST['payment']=='Confirm totals and make payment.')
{
	foreach($_POST['id_registrant'] as $key=>$value)
	{
		$fieldname=htmlentities($key,ENT_QUOTES,'UTF-8');
		$fieldvalue=intval($value);
		echo sprintf('<div>%s: %d<input type="hidden" name="id_registrant[%s]" value="%d"/></div>',$fieldname,$fieldvalue,$fieldname,$fieldvalue);
	}
}

Open in new window


NOTE: If you were to change the names of your input elements from:
<input type="text" name="id_registrant[lastname63700]" id="id_amount1">

to something like:
<input type="text" name="id_registrant[firstname lastname__63700]" id="id_amount1">

then you could split $key at the double underline to get the first and last names:
if(isset($_POST['payment']) && $_POST['payment']=='Confirm totals and make payment.')
{
	foreach($_POST['id_registrant'] as $key=>$value)
	{
		$temp=explode('__',$key);
		$fullname=htmlentities($temp[0],ENT_QUOTES,'UTF-8');
		$fieldname=htmlentities($key,ENT_QUOTES,'UTF-8');
		$fieldvalue=intval($value);
		echo sprintf('<div>%s: %d<input type="hidden" name="id_registrant[%s]" value="%d"/></div>',$fullname,$fieldvalue,$fieldname,$fieldvalue);
	}
}

Open in new window

0
 
LVL 2

Author Closing Comment

by:stkoontz
ID: 39725256
Thanks for the help.  That worked!

Steve
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL-Design Help 12 67
How to use 2 ON statements in inner join 3 45
How to close my php post page. 3 42
Prestashop modules custimzation 2 28
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

751 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