How to pass multiple post array variables in PHP

I have a program that has a list of elements I want to save the state of when I load another page. Here’s how I generate the form so it will include all the elements in a post array variable.

echo "<td><form name='input' action='go.php' method='POST'>";

foreach($post_arr as $postvar)
{
	echo "<input type='hidden' name='post_arr[]' value='".$postvar."'>";
}

echo "<input type='image' src='buttons/go.png' width=24 alt='submit'>
	  </form></td>";

Now when go.php loads, you can check to see if there’s anything in the post_arr, and if there is, cycle through the array and store all the elements. I couldn’t find a working example of this just by googling. It seemed like tons of people would ask for this, but any responses on forums would be, “well what are you really trying to do”. So here it is.

$arr = array();
if (ispostset("post_arr"))
{
    foreach($_POST['post_arr'] as $postvar)
	$arr[] = $postvar;
}

I use these in the same php file so it can reload and change the way it displays. I allow the user of go.php to toggle things and change entries in a table or list and resubmit.

Posted by admica   @   6 August 2009
Tags : , , , , , ,

Related Posts

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Using PHP’s explode to split a full path into directory and file name
Next Post
Toggling debug output within a PHP class »
Powered by Wordpress   |   Lunated designed by ZenVerse