Unless I'm missing something obvious, in any multiple selection form element there is only one name or id so would you need more than 1D?
Just append [] to the form element name and it ends up as $_POST['name'] as an array after submit, i.e.
Code:
<input type='checkbox' name='options[]' value='1' /> Item one
<input type='checkbox' name='options[]' value='2' /> Item two
PHP Code:
print_r($_POST['options']);
Aside from form submission, you can pass arrays of any dimension using session variables from page to page if you wish. Just remember -- unlike a real PHP multidimensional array, $_SESSION keys at the root level must be valid variable names, not numbers.
Within the same domain, the session option suggested above is probably more efficient than sending the data via post. But if you do need to send it via post for some reason (such as a cURL request to another site or something), you can serialize() the array and send the resulting string as a single post field, then unserialize() it in the receiving script.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
and you wanted to pull just the "full_name" you can
PHP Code:
foreach ($_POST['full_name'] as $name) { echo $name."\n"; }
and you get
Aaron Whistler Jr.
Wendy Buttons
and if you want to pull the "full_name" AND "year_salary" AND "job_title" AND "co_name" you can do this by using one of them to get the indexes
PHP Code:
for ($i=0; $i < count($_POST['full_name']); $i++) { echo $_POST['full_name'][$i]." earns "; echo $_POST['year_salary'][$i]." per year as "; echo $_POST['job_title'][$i]." at "; echo $_POST['co_name'][$i].".\n"; }
and you get
Aaron Whistler Jr. earns $1,000,000 per year as assistant mailboy at Whoopee Incorporated.
Wendy Buttons earns $40,000 per year as SysAdmin at WeRtheBest DotCOMM.
But, there are other options depending on what you need to do.
Since you're generating an xml anyway, you're way ahead of the game!
Just parse the xml for your stats box info... no sense in doing more work than you have to.
Since you're generating an xml anyway, you're way ahead of the game!
Just parse the xml for your stats box info... no sense in doing more work than you have to.
...or am I missing something?
Okay, what's going on is this is part of a larger update setup: guys who know how to do statistics but not XML use the form to in the numbers. The script generates the XML. They send me the XML, and I add it to a larger XML file.
Refer to reply #3 for command help - If you have XML multi-dimensional array data prior to generating the form serialize it and pass it as one value, the on form submit in your processing script unserialize and you get back the original data.
Bookmarks