Page 1 of 1

Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 7:14 pm
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.

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 7:35 pm
by califdon
Post data is in the form of name-value pairs. Can't you just assign the variables based on that?

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 7:39 pm
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

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 8:04 pm
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));

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 8:09 pm
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

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 8:12 pm
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
 
 

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 8:20 pm
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.

Re: Post Form Data - Which Order - Browser?

Posted: Tue Apr 15, 2008 8:23 pm
by ianhull
Thanks jcart,

very much appreciated,

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