Form field info after a post

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
phpnewb33
Forum Newbie
Posts: 2
Joined: Mon Sep 29, 2003 9:49 am
Location: Minneapolis

Form field info after a post

Post by phpnewb33 »

I am trying to create a dynamic select query based on a list of form elements submitted from the previous screen.

What i wold like to do is loop through the submitted fields and compare them to the fields in a db table with the same names. I can easily get the values from the fields, but i cannot find the function or variable to get the array of form field names.

Can anyone point me in the right direction?

Thanks!
styrmstread
Forum Newbie
Posts: 4
Joined: Mon Sep 29, 2003 11:09 am

Post by styrmstread »

if i understand you correctly, here is what you can do,

if the form is submitted by the POST method use the following to loop through these form fields.

Code: Select all

while (list($var,$val) = each($HTTP_POST_VARS))
         { ....}
In this case $var is the formfield name, and $val is the value associated with this field.
Once in this loop you can check names using something like

Code: Select all

if (ereg("^nnn",$var,$throwaway))
  {   
   ....
  }
ereg checks $var to see if nnn are the first three characters of its value.
you can then perform your process conditionally dependent upon which form field $var is pointing to.
I hope this makes sense...let me know if you don't understand.
Styrmstread
phpnewb33
Forum Newbie
Posts: 2
Joined: Mon Sep 29, 2003 9:49 am
Location: Minneapolis

Post by phpnewb33 »

styrmstread,

Thanks for your help! This is exactly what i needed...

-gary
junky
Forum Commoner
Posts: 30
Joined: Wed Sep 03, 2003 3:58 pm

Post by junky »

what to say more ? except that styrmstread is a good teacher :)

$_POST isnt the new standard replacing the $HTTP_POST_VARS ? 8)
Post Reply