Re: [PHP] order of elements in $_POST super global
On Thu, June 8, 2006 9:59 am, Ben Liu wrote: I'm using a form (method=POST) to collect 30 boolean values from the end user using a series of checkboxes in the form. The form is arranged in a table so that the 30 check boxes are not a long list but rather three columns (with related items columnized). The problem is when I iterate through the $_POST results: The order in which I wish to present the checkboxes to the end user is different than the order I want to have in the $_POST super global and subsequently when I dump that information out to a text file. You CANNOT rely on the browser to send POST data in any particular order, by the HTTP spec. While it's true that ALL known browsers send them in the order they appear in the HTML, they don't have to. And, of course, if they ever change that, a zillion scripts will break... Still, better safe than sorry. What would be the best way to solve this? Since you want them in a particular order, use the KEY of the array to order them: input type=checkbox name=array[0] / I'm first. input type=checkbox name=array[1] / I'm second. input type=checkbox name=array[2] / I'm third. 1) Is there a way to present the checkboxes in a certain order, yet have the data transmitted into the $_POST super global in a different order? Presentation order is all HTML. 2) Does it make more sense to process the $_POST super global array and reorder the items within the array? 3) Some other method? Thanks for any advice. - Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] order of elements in $_POST super global
Hello All, I'm using a form (method=POST) to collect 30 boolean values from the end user using a series of checkboxes in the form. The form is arranged in a table so that the 30 check boxes are not a long list but rather three columns (with related items columnized). The problem is when I iterate through the $_POST results: The order in which I wish to present the checkboxes to the end user is different than the order I want to have in the $_POST super global and subsequently when I dump that information out to a text file. What would be the best way to solve this? 1) Is there a way to present the checkboxes in a certain order, yet have the data transmitted into the $_POST super global in a different order? 2) Does it make more sense to process the $_POST super global array and reorder the items within the array? 3) Some other method? Thanks for any advice. - Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] order of elements in $_POST super global
On 08/06/06, Ben Liu [EMAIL PROTECTED] wrote: Hello All, I'm using a form (method=POST) to collect 30 boolean values from the end user using a series of checkboxes in the form. The form is arranged in a table so that the 30 check boxes are not a long list but rather three columns (with related items columnized). The problem is when I iterate through the $_POST results: The order in which I wish to present the checkboxes to the end user is different than the order I want to have in the $_POST super global and subsequently when I dump that information out to a text file. What would be the best way to solve this? 1) Is there a way to present the checkboxes in a certain order, yet have the data transmitted into the $_POST super global in a different order? 2) Does it make more sense to process the $_POST super global array and reorder the items within the array? 3) Some other method? Thanks for any advice. - Ben You can access the values in the $_POST array in any order, so if you know the checkbox names why not output them in the order you want? Or I am being dumb here? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://www.web-buddha.co.uk dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css) look out for project karma, our new venture, coming soon!
Re: [PHP] order of elements in $_POST super global
Hi Dave, No, that is definitely a possibility. Right now I am using a foreach loop to iterate over the $_POST array and determine if each checkbox is checked or not, if it is checked, than a related piece of data is written into the text file. This makes for pretty compact code. I could as you suggest, simply check each element in the array manually using the associative keys rather than using a loop, that way I could do it in any order I wished, but the code gets rather long with a line for each checkbox. I anticipate this set of checkboxes/boolean responses may increase in the future also, so having the loop allows for some future-proofing. - Ben On 6/8/06, Dave Goodchild [EMAIL PROTECTED] wrote: On 08/06/06, Ben Liu [EMAIL PROTECTED] wrote: You can access the values in the $_POST array in any order, so if you know the checkbox names why not output them in the order you want? Or I am being dumb here? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] order of elements in $_POST super global
Ben Liu wrote: Hi Dave, No, that is definitely a possibility. Right now I am using a foreach loop to iterate over the $_POST array and determine if each checkbox is checked or not, if it is checked, than a related piece of data is written into the text file. This makes for pretty compact code. I could as you suggest, simply check each element in the array manually using the associative keys rather than using a loop, that way I could do it in any order I wished, but the code gets rather long with a line for each checkbox. I anticipate this set of checkboxes/boolean responses may increase in the future also, so having the loop allows for some future-proofing. - Ben On 6/8/06, Dave Goodchild [EMAIL PROTECTED] wrote: On 08/06/06, Ben Liu [EMAIL PROTECTED] wrote: You can access the values in the $_POST array in any order, so if you know the checkbox names why not output them in the order you want? Or I am being dumb here? why not create an array with the keys in the order you want ( $array= array(value1,value2,). Then loop through the array and use the values as keys to the $_POST variable and perform your processing that way. foreach ($array as $value) { if (isset($_POST[$value]) { do something; } } -- Ron Clark System Administrator Armstrong Atlantic State University -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] order of elements in $_POST super global
Der...of course. Thanks Ron! I knew the answer was simple. :-) -Ben On 6/8/06, Ron Clark [EMAIL PROTECTED] wrote: why not create an array with the keys in the order you want ( $array= array(value1,value2,). Then loop through the array and use the values as keys to the $_POST variable and perform your processing that way. foreach ($array as $value) { if (isset($_POST[$value]) { do something; } } -- Ron Clark System Administrator Armstrong Atlantic State University -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php