Post Form Data - Which Order - Browser?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post Form Data - Which Order - Browser?

Post by ianhull »

Hi all,

Well I find myself here once again, this time here is my question.

If I post a form to a php page using IE in which order is the form proccessed?

For example my form page contains userTitle, userFirstName and userSurName

When this is recieved by my php page which is proccessed first? I'm assuming it will be userTitle as this is at the top of my form, then next userFirstName, however, I am unsure and even more unsure if this works differently for FF Opera etc.

my idea is to have all posted data placed into an array and sent to a function so that Instead of using formField Names like userTitle I can use just one name for example

myFormElement[] as the userTitle
myFormElement[] as the userFirstName

Code: Select all

 
 
function myFunction($theAction, $thePostedData){
 
if($theAction == 'INSERT'){
//do this
 
$userTitle = $thePostedData[0];
$userFirstName = $thePostedData[1];
 
};
 
if($theAction == 'UPDATE'){
//do this
};
 
}://end function
 
 
 

//MyPHPPage

Code: Select all

 
 
$myPostedData = array();
 
foreach($_POST as $theKey => $theValue){
 
$myPostedData[] = $theValue;
 
};//end foreach
 
myFunction('INSERT', $myPostedData);
 
 
you get the idea

any help on this is greatly appreciated.
Thanks in advance.
Last edited by ianhull on Tue Apr 15, 2008 7:36 pm, edited 1 time in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Post Form Data - Which Order - Browser?

Post by califdon »

Post data is in the form of name-value pairs. Can't you just assign the variables based on that?
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Re: Post Form Data - Which Order - Browser?

Post by ianhull »

Thanks califdon,

I just made a few changes to my post while you was replying,

I could but I am in the end wanting to write a class file which just makes it so much easier for management etc.

Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Post Form Data - Which Order - Browser?

Post by John Cartwright »

If I may be blunt, that is the complete opposite of what I consider manageable. Someone coming across your code will not know what $postdata[4] is unless they go your form and count the elements in which they appear. Ouch.

To answer your question, the post data is processed in the order it appears in the html.

Side note, no need to loop to get the values of $_POST into a seperate array.

Code: Select all

myFunction('INSERT', array_values($_POST));
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Re: Post Form Data - Which Order - Browser?

Post by ianhull »

Thanks

I appreciate your comments, however, there will only ever be me updating this system and I will have a reference to everything in place.

Thanks for the tip on the $_POST, was not aware of that one.

Do you know if this is the same for all browsers?
Do all browsers send the form in the order it is on the html page too?

Thanks
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Re: Post Form Data - Which Order - Browser?

Post by ianhull »

After a quick thought based on your replies I gues I will not go about it that way :)

Any comments on this one is greatly appreciated.

Code: Select all

 
 
$myPostedData = array();
 
foreach($_POST as $theKey => $theValue){
 
$myPostedData['$theKey'] = $theValue;
 
};//end foreach
 
 
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Post Form Data - Which Order - Browser?

Post by John Cartwright »

Code: Select all

$myPostedData = array();
foreach($_POST as $theKey => $theValue){
   $myPostedData['$theKey'] = $theValue;
};//end foreach

Code: Select all

$myPostedData = $_POST;
Simple enough ;)

FYI, you cannot parse variables within single quotes.
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Re: Post Form Data - Which Order - Browser?

Post by ianhull »

Thanks jcart,

very much appreciated,

I noticed the single quotes error when I typed it onto Dreamweaver :) thanks again.
Post Reply